java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
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());
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()错误解决 2012年03月27日 15:47:52 katalya 阅 ...
- Can not issue data manipulation statements with executeQuery().解决方案
这个错误提示是说无法发行sql语句到指定的位置 错误写法: 正确写法: excuteQuery是查询语句,而我要调用的是更新的语句,所以这样数据库很为难到底要干嘛,实际我想用的是更新,但是我写成了查询 ...
- Can not issue data manipulation statements with executeQuery()的解决方案
Can not issue data manipulation statements with executeQuery() 报错的解决方案: 把“ResultSet rs = statement. ...
- Can not issue data manipulation statements with executeQuery() 异常处理
1.这个异常的报错翻译过来就是 不能发出数据操纵语句与executeQuery() 2.这里要检查一下你要执行的实际SQL语句要做什么操作 查询呢?还是修改? 3.如果是修改的话,需要添加@Modif ...
- Can not issue data manipulation statements with executeQuery().解决的方法
query是查询用的,而update是插入和更新,删除修改用的. executeQuery()语句是用于产生单个结果集的语句,如select语句,在什么情况下用,当你的数据库已经保存了数据后,要进行查 ...
- Can not issue data manipulation statements with executeQuery().
这个错误提示是说无法发行sql语句到指定的位置 就是如图的两端代码的问题,excuteQuery是查询语句,而我要调用的是更新的语句,所以这样数据库很为难到底要干嘛,我实际的操作是要更新数据,所以把 ...
- FSG报表打印报错,log文件显示java.sql.SQLException: No corresponding LOB data found
报错信息: +---------------------------------------------------------------------------+ Plsql 程序的日志信息开始 ...
- java.sql.SQLException: Can not issue empty query.
1.错误描述 java.sql.SQLException: Can not issue empty query. at com.mysql.jdbc.SQLError.createSQLExcepti ...
- java.sql.SQLException: Can not issue executeUpdate() for SELECTs
未处理的多个select语句 解决方法就是:查看有没有用了同一个连接来处理多个SQL语句!
随机推荐
- JavaScript组成(三个组成部分)
JavaScript主要包括三部分: 1.ECMAScript: JavaScript的核心,仅仅是一个描述,定义了脚本语言的所有属性,方法和对象. 具体地,ECMAscript描述了以下内容: 语法 ...
- 【G彩娱乐网】作为一名程序员,我应该如何选购一台电脑?
G彩娱乐网说到程序员专用电脑,那肯定是苹果电脑.优点有很多,比如白平衡特别准.酷炫的黑科技.特别方便的软件等显而易见的优势:也有能够增加提案通过率.专注工作提高工作效率这样的玄学buff. 但是!并不 ...
- lvs学习笔记
本人身为一个网工,最近一直在工作中学习linux的相关知识.前短时间通过自查资料学习了lvs的相关内容,摘录部分整理后和大家分享,内容较多,较琐碎,望见谅!!! LVS 从Linux内核版本2.6起, ...
- win10出现"本地计算机上的MySQL57服务启动后停止"
在window10下mysql57出现"本地计算机上的MySQL57服务启动后停止.某些服务在未由其他服务或程序使用时将自动停止"错误 环境:win10.MySQL Communi ...
- JavaScript 面试中常见算法问题详解
1.阐述下 JavaScript 中的变量提升 所谓提升,顾名思义即是 JavaScript 会将所有的声明提升到当前作用域的顶部.这也就意味着我们可以在某个变量声明前就使用该变量,不过虽然 Java ...
- vue 2 仿IOS 滚轮选择器 从入门到精通 (一)
大家好,由于最近从事的是微信公众号和APP内嵌 H5开发,避免不了开发一些和native相同的操作功能,就如接下来说的 仿IOS滚轮选择器. 先来个截图: 接下来具体介绍如何实现的.能力有限避免不了错 ...
- Windows定时器学习
定时器是一个在特定时间或者规则间隔被激发的内核对象.结合定时器的异步程序调用可以允许回调函数在任何定时器被激发的时候执行. 通过调用CreateWaitableTimer()可以创建一个定时器,此函数 ...
- [转载] gitbook安装与使用
转载自http://blog.csdn.net/xiaocainiaoshangxiao/article/details/46882921 废话不说,直接主题: gitbook安装 ========= ...
- android 加载图片圆角等功能的处理
以Glide为例: Glide.with(getContext()).load(item.getSoftLogo()).transform(this.glideRoundTransform).into ...
- Linux下安装Redis php-redis扩展 redis重启shell脚本 超详细!
前言 前面刚写过nosql其中三款热门产品的对比,这次主要写关于Redis的一些事情,Redis的介绍.安装以及扩展(php-redis,因为我是phper)安装等等.同时是写给我的朋友(cccjjj ...