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().的更多相关文章

  1. Can not issue data manipulation statements with executeQuery()错误解决

    转: Can not issue data manipulation statements with executeQuery()错误解决 2012年03月27日 15:47:52 katalya 阅 ...

  2. Can not issue data manipulation statements with executeQuery().解决方案

    这个错误提示是说无法发行sql语句到指定的位置 错误写法: 正确写法: excuteQuery是查询语句,而我要调用的是更新的语句,所以这样数据库很为难到底要干嘛,实际我想用的是更新,但是我写成了查询 ...

  3. Can not issue data manipulation statements with executeQuery()的解决方案

     Can not issue data manipulation statements with executeQuery() 报错的解决方案: 把“ResultSet rs = statement. ...

  4. Can not issue data manipulation statements with executeQuery() 异常处理

    1.这个异常的报错翻译过来就是 不能发出数据操纵语句与executeQuery() 2.这里要检查一下你要执行的实际SQL语句要做什么操作 查询呢?还是修改? 3.如果是修改的话,需要添加@Modif ...

  5. Can not issue data manipulation statements with executeQuery().解决的方法

    query是查询用的,而update是插入和更新,删除修改用的. executeQuery()语句是用于产生单个结果集的语句,如select语句,在什么情况下用,当你的数据库已经保存了数据后,要进行查 ...

  6. Can not issue data manipulation statements with executeQuery().

    这个错误提示是说无法发行sql语句到指定的位置 就是如图的两端代码的问题,excuteQuery是查询语句,而我要调用的是更新的语句,所以这样数据库很为难到底要干嘛,我实际的操作是要更新数据,所以把 ...

  7. FSG报表打印报错,log文件显示java.sql.SQLException: No corresponding LOB data found

    报错信息: +---------------------------------------------------------------------------+ Plsql 程序的日志信息开始 ...

  8. java.sql.SQLException: Can not issue empty query.

    1.错误描述 java.sql.SQLException: Can not issue empty query. at com.mysql.jdbc.SQLError.createSQLExcepti ...

  9. java.sql.SQLException: Can not issue executeUpdate() for SELECTs

    未处理的多个select语句 解决方法就是:查看有没有用了同一个连接来处理多个SQL语句!

随机推荐

  1. 如何优雅的设计React组件

    如何优雅的设计 React 组件 如今的 web 前端已被 React.Vue 和 Angular 三分天下,一统江山十几年的 jQuery 显然已经很难满足现在的开发模式.那么,为什么大家会觉得 j ...

  2. PowerShell安全修改Windows 10 登陆背景图

    PowerShell安全修改Windows 10 登陆背景图 可以把登陆的背景图换掉,主要是修改操作pri文件 $priPath = "$env:windir\SystemResources ...

  3. java变量与内存深入了解

    ========================================================================================= 在我看来,学习jav ...

  4. 【分享】纯jQuery实现星巴克官网导航栏效果

    前言 大冬天的没得玩,只能和代码玩. 所以就无聊研究了一下星巴克官网,在我看来应该是基本还原吧~ 请各位大神指教! 官网效果图 要写的就是最上方的会闪现的白色条条 效果分析 1.在滚动条往下拉到一定距 ...

  5. OpenTSDB-Querying or Reading Data

    Querying or Reading Data OpenTSDB offers a number of means to extract data such as CLI tools, an HTT ...

  6. python之optparse模块

    测试例子 #!/usr/bin/env python2.7 import sys import os from optparse import OptionParser def parse_optio ...

  7. Android OOM异常解决方案

    一,什么是OOM异常: OOM(out of Memory)即内存溢出异常,也就是说内存占有量超过了VM所分配的最大,导致应用程序异常终止: 二,为什么会产生OOM异常呢? OOM异常是Android ...

  8. Winwos Server 2012发布ASP.NET MVC5 项目

    一.本文实验环境: Windows Server 2012 R2 Visual Studio 2015 项目为:ASP.NET MVC 5.0,使用的是SQL SERVER 2008 R2数据库 二. ...

  9. vue-router在ie9及以下history模式支持

    参考: https://www.npmjs.com/package/vue-route https://github.com/devote/HTML5-History-API 提要: ie9及以下不支 ...

  10. 书籍推荐系列之一 -- 《凤凰项目:一个IT运维的传奇故事》

    博客已经完全更新了名字,新的名字,新的开始,想让自走向新的道路是很难的,走出舒适圈说了好久,也是时候开始行动了,今天就从写博客开始. 今天给大家推荐一本书,<凤凰项目:一个IT运维的传奇故事&g ...