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语句!
随机推荐
- Problem B: 开个餐馆算算账
Description 小明创业了!他开了一家餐馆,每天客人还挺多的.每天下班后,他都要算算今天总共收入多少钱,但是手工算太麻烦了,所以他来向你求助了. Input 第1行N>0,表示餐馆提供N ...
- Cisco VPN Client Win10无法使用的解决办法
http://files.cnblogs.com/files/Flyear/VPN_Win10_ByDuke.zip 1. 关闭系统所有窗口,控制面板一定要关闭. 2. 运行winfix.exe, 按 ...
- SSL证书简介
前言 之前写了一篇本站点如何部署SSL证书的文章<Centos7.4下用Docker-Compose部署WordPress(续)-服务器端用Nginx作为反向代理并添加SSL证书(阿里云免费DV ...
- netty常用使用方式
最近在重新看netty,在这里总结一些netty的一些常用的使用方式,类似于模板,方便速查. 以netty 4.1.x的API作记录,不同版本可能API有略微差异,需要注意netty5被废弃掉了(辨别 ...
- c#把汉字转化成全拼音函数(全拼)
/// <summary> /// 把汉字转换成拼音(全拼) /// </summary> /// <param name=&q ...
- .Net中的装箱和拆箱
装箱(boxing)和拆箱(unboxing)是.NET提出得新概念!.NET的所有类型都是由基类System.Object继承过来的,包括最常用的基础类型:int, byte, short,bool ...
- struts2 内容记录
多xml文件配置 在开发过程中我们经常会将每一张表(如:user表)的struts.xml文件分开,便于管理,故需要建立struts_user.xml文件管理请求等.那么需要用到inculde标签. ...
- vimgdb安装以及使用
vimgdb安装 vim-7.3.tar.bz2http://www.vim.org/sources.phpvimgdb-for-vim7.3 (this patch) https://github. ...
- SpringAware
哈哈,终于把分布式的课程演讲给混过去了,下面开始随便自己学点东西. 正题:SpringAware--------在实际项目中,用到spring容器的本省功能资源,这是Bean必须意识到Spring容器 ...
- 逻辑回归,附tensorflow实现
本文旨在通过二元分类问题.多元分类问题介绍逻辑回归算法,并实现一个简单的数字分类程序 在生活中,我们经常会碰到这样的问题: 根据苹果表皮颜色判断是青苹果还是红苹果 根据体温判断是否发烧 这种答案只有两 ...