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语句!
随机推荐
- jQuery选择器(层级选择器)第二节
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...
- HTML DOM应用案例1
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 收集—— css实现垂直居中
Method1: 在父元素上设置display:table-cell;vertical-align:middle(父元素不能设置浮动) Method2: 使用flex:父元素设置成display: f ...
- hadoop的webUI查看Live Nodes为1
开起了两个节点,而且jps查看确实开启了,但是用web端50070查看却一直显示为1 经过排查,将虚拟机直接copy一份,但是之前配置好hadoop环境的namenode格式化(format)生成的文 ...
- Linux常用命令100个用法
平时用linux时,我有一个习惯就是把遇到的,比较有用,并且容易忘的命令,放到一个文本文件中,没事的时候可以拿出来看看,这样可以加深映像,时间长了这些命令的用法基本上都能掌握了.以下是100个用法,有 ...
- jQuery的事件绑定命名空间
jQuery的bind的函数在实际应用中用的不是特别多,只是他可以绑定一个事件,但不会即时触发,也可以通过unbind来解除绑定.在没有看到这篇文章之前,我一直不知道原来bind也可以有命名空间.事实 ...
- web前端-----JAVA Script(一)
JavaScript概述 JavaScript的历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase ...
- gdb分析core文件
转载自:http://blog.chinaunix.net/u2/83905/showart_2134570.html 在Unix系统下,应用程序崩溃,一般会产生core文件,如何根据core文件查找 ...
- maven学习之二
三 profile介绍 可以有多个地方定义profile.定义的地方不同,它的作用范围也不同. (1) 针对于特定项目的profile配置我们可以定义在该项目的pom.xml中. (2) ...
- django作业2
管理后台 1.登陆Form 2.Session (用装饰器实现) 3.装饰器 4.主机,主机组 添加(主机,主机组) 删除 修改 查询