java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
来源:互联网 发布:淘宝轮毂店 编辑:程序博客网 时间:2024/05/21 06:55
1、错误描述
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:870)at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:472)at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1401)at com.you.sql.Student.commonMethod(Student.java:117)at com.you.sql.Student.insertStudent(Student.java:86)at com.you.sql.Student.main(Student.java:181)
2、错误原因
public static void insertStudent(){StringBuffer sql = new StringBuffer();int j = 0;String str = "0";for(int i=5;i<1000;i++){++j;if(i%2 == 0){str = "0";}else{str = "1";}sql.append("insert into t_stu_info (").append(i).append(",").append(103+j+"").append(",") .append("zhangsan"+(i-4)).append(",").append(str).append(",") .append(Integer.parseInt(Math.round(Math.random()*10+20)+"")).append(",") .append("123"+i);}commonMethod(sql.toString());}
/** * * @Title:Student * @Description: * @param sqlStu * @Date:2015年6月11日 上午12:25:56 * @return :void * @throws */public static void commonMethod(String sqlStu){StringBuffer sql = new StringBuffer();sql.append(sqlStu);Connection conn = null;Statement stat = null;ResultSet rs = null;try {try {Class.forName(DRIVER_CLASS);} catch (ClassNotFoundException e) {e.printStackTrace();}conn = DriverManager.getConnection(URL, USER, PASSWORD);stat = conn.createStatement();rs = stat.executeQuery(sql.toString());while(rs.next()){String stuId = rs.getString("stu_id");String stuName = rs.getString("stu_name");String stuSex = rs.getString("sex");String stuAge = rs.getString("stu_age");String stuPhone = rs.getString("stu_phone");System.out.println("学号:"+stuId+"----"+"姓名:"+stuName+"----"+"性别:"+stuSex+"---"+"年龄:"+stuAge+"----"+"电话:"+stuPhone);}} catch (SQLException e) {e.printStackTrace();}finally{if(rs != null){try {rs.close();} catch (SQLException e) {e.printStackTrace();}}if(stat != null){try {stat.close();} catch (SQLException e) {e.printStackTrace();}}if(conn != null){try {conn.close();} catch (SQLException e) {e.printStackTrace();}}}}
3、解决办法
由于在执行插入操作时,调用了executeQuery方法,出现错误;插入操作应该调用executeUpdate方法
int result = stat.executeUpdate(sql.toString());
1 0
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- java.sql.SQLException:Can not issue data manipulation statements with executeQuery()
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- Caused by: java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery()
- Can not issue data manipulation statements with executeQuery()错误解决
- Can not issue data manipulation statements with executeQuery()错误解决
- Can not issue data manipulation statements with executeQuery()错误解决
- Can not issue data manipulation statements with executeQuery().
- 兔子-- Can not issue data manipulation statements with executeQuery()
- Can not issue data manipulation statements with executeQuery()解决方案
- Can not issue data manipulation statements with executeQuery()
- Can not issue data manipulation statements with executeQuery()
- Can not issue data manipulation statements with executeQuery()错误解决
- Can not issue data manipulation statements with executeQuery().
- JavaBean链接MySQL数据库错误aq.executeQuery.Can not issue data manipulation statements with executeQuery()解决
- Can not issue data manipulation statements with executeQuery().问题的解决
- HBase表的架构原理
- 驻足,为了更好的驶向下一站
- 黄昏时刻挂满树梢的AE相册模板
- Python基础教程笔记——字典:当索引不好用时
- ASIHTTPRequest开源类项目导入问题及解决方法
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
- JAVA 计算地球上任意两点(经纬度)距离
- 仁义礼智信,温良恭俭让
- mysql explain 的type解释
- 求平方根——分治法
- Multipath多路径冗余全解析
- Sublime报Decode error - output not utf-8 or cp936 错误的解决办法
- bean的5种作用域
- 学习什么是RESTful(Representational State Transfer)(原创+转载)