亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

關于java.sql.SQLException: Can not issue data manipulation statements with executeQuery().

pstereo 2016-11-27 19:07:06
報出上面那個錯誤應該怎么解決呢,急求?。?!程序:import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class TestPrepareStatement {? public static void main(String[] args){ ?ResultSet rs=null;? Statement stmt=null;? Connection conn=null;? PreparedStatement pstmt=null;? try{? Class.forName("com.mysql.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/yuangong","root",""); stmt=conn.createStatement(); pstmt=conn.prepareStatement("insert into yuangongbiao values(?,?,?,?,?)"); /*添加的第一條記錄*/ pstmt.setInt(1, 1004); pstmt.setString(2, "Lily"); pstmt.setString(3, "[email protected]"); pstmt.setInt(4, 3600); pstmt.setString(5, "1999-02-13"); /*添加的第二條記錄*/ pstmt.setInt(1, 1005); pstmt.setString(2, "Li"); pstmt.setString(3, "[email protected]"); pstmt.setInt(4, 3200); pstmt.setString(5, "1979-02-13"); /*添加的第三條記錄*/ pstmt.setInt(1, 1006); pstmt.setString(2, "Wang"); pstmt.setString(3, "[email protected]"); pstmt.setInt(4, 3000); pstmt.setString(5, "1994-02-13"); pstmt.executeQuery(); rs=stmt.executeQuery("select * from yuangongbiao"); while(rs.next()){ System.out.print(rs.getInt("employee_id")); System.out.print(rs.getString("name")); System.out.print(rs.getString("email")); System.out.print(rs.getInt("salaty")); System.out.print(rs.getString("birthday")); }? }catch(ClassNotFoundException e){? e.printStackTrace();? }catch(SQLException e){? e.printStackTrace();? }finally{? try{? if(rs!=null){? rs.close();? rs=null;? }? if(pstmt!=null){? pstmt.close();? pstmt=null;? }? if(stmt!=null){? stmt.close();? stmt=null;? }? if(conn!=null){? conn.close();? conn=null;? }? }catch(SQLException e){? e.printStackTrace();? }? } ?? }}
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 4063 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號