为了账号安全,请及时绑定邮箱和手机立即绑定

关于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, "Lily@126.com"); pstmt.setInt(4, 3600); pstmt.setString(5, "1999-02-13"); /*添加的第二条记录*/ pstmt.setInt(1, 1005); pstmt.setString(2, "Li"); pstmt.setString(3, "Li@126.com"); pstmt.setInt(4, 3200); pstmt.setString(5, "1979-02-13"); /*添加的第三条记录*/ pstmt.setInt(1, 1006); pstmt.setString(2, "Wang"); pstmt.setString(3, "Wang@126.com"); 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 关注
  • 4012 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信