java.sql.SQLException: Can not issue empty query.
1、错误叙述性说明
java.sql.SQLException: Can not issue empty query.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.checkNullOrEmptyQuery(StatementImpl.java:492)at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1367)at com.you.sql.Student.queryStudent(Student.java:51)at com.you.sql.Student.main(Student.java:79)
2、错误原因
/*** * @Project:MySQL* @Title:Student.java* @Package:com.you.sql* @Description:* @Author:YouHaiDong* @Date:2015年6月10日 下午11:49:36* @Version:*/
package com.you.sql;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;/*** <p>请用一句话概括功能</p>* @ClassName:Student* @Description:* @Author:YouHaiDong* @Date:2015年6月10日 下午11:49:36* */
public class Student
{/*** 查询学生基本信息* @Title:Student* @Description:* @Date:2015年6月11日 上午12:06:40* @return :void * @throws*/public static void queryStudent(){StringBuffer sql = new StringBuffer();String url = "jdbc:mysql://localhost:3333/student";String user = "root";String password = "root";Connection conn = null;Statement stat = null;ResultSet rs = null;try {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();}}/*** * @Title:Student* @Description:* @param args* @Date:2015年6月11日 上午12:07:53* @return :void * @throws*/public static void main(String args[]){queryStudent();}
}
3、解决的方法
因为在运行rs = stat.executeQuery(sql.toString());时,sql为空。导致报错
StringBuffer sql = new StringBuffer();
sql.append("select * from t_stu_info ");
版权声明:本文博主原创文章,博客,未经同意不得转载。
java.sql.SQLException: Can not issue empty query.相关推荐
- mysql5.5异常: java.sql.SQLException: Packet for query is too large (1055975 1048576).
参考:http://blog.csdn.net/zhangzeguang88/article/details/21383667 mysql5.5异常: java.sql.SQLException: P ...
- Cause: java.sql.SQLException: SQL String cannot be empty 解决方案
异常信息: Cause: java.sql.SQLException: SQL String cannot be empty 产生原因: 在批量进行SQL更新(或插入)时,有的时候会报错,有的时候不会 ...
- java.sql.SQLException: Table 'test.customer' doesn't exist Query: Select id,name,address,phone from
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 5, ...
- mysql5.5异常: java.sql.SQLException: Packet for query is too large (1055975 > 1048576).
mysql5.5异常: java.sql.SQLException: Packet for query is too large (1055975 > 1048576). mysql5.5异常: ...
- java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result
java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result s ...
- java.sql.SQLException: Lock wait timeout exceeded
2019独角兽企业重金招聘Python工程师标准>>> 先说我我的解决方法:找到锁住的线程然后kill掉. mysql> kill thr_id; 下面简单分析一下到底应该ki ...
- Oracle Caused by: java.sql.SQLException: sql injection violation, syntax error: syntax error, expect
参考:https://blog.csdn.net/qq_36326332/article/details/102938147 https://blog.csdn.net/fly_captain/art ...
- ORACLE各种常见java.sql.SQLException归纳
java.sql.SQLException错误! ORA-00904: --invalid column name 无效列名 ORA-00942: --table or view does n ...
- oracle错误(一) ORA-各种常见java.sql.SQLException小结
ORA-00904: --invalid column name 无效列名ORA-00942: --table or view does not exist 表或者视图不存在ORA-01400: -- ...
最新文章
- spring MVC要注意的地方 2
- 在LINUX下安装 Sybase ASE 11.0.3.3
- python标准库的图像处理模块_PIL:Python Imaging Library(图像处理标准库)
- 用c#语言制作ktv点歌系统,KTV点歌系统的设计与实现的设计和实现(C#,C/S,Access)
- 使用ActiveMQ实现简易聊天功能
- 什么无线蓝牙耳机好?英雄联盟推荐竞技游戏专用蓝牙耳机
- 六自由度机器人(机械臂)运动学建模及运动规划系列(一)——简介
- 数据分析 超市条码_超市小程序做得比较好的功能点是什么?
- python怎么算二元一次方程_Python简单实现二元一次方程求根
- dell加装固态硬盘_戴尔(dell)计算机nvme固态硬盘安装win10系统和分区教程
- 远程手机教学|简单实用,1键远程协助老人使用智能手机
- SolidWorks Simulation 2014有限元分析培训视频教程
- GraphQL的认识与使用
- Macbook Pro M1安装Homebrew跟git安装
- 编写程序,解决鸡兔同笼问题:一个笼子里关着鸡和兔子。问笼中各有多少只鸡和兔?
- 众达说两化融合A042A=程序文件之信息资源需要包含那些内容
- localforage前端本地存储
- 六年级计算机课学什么意思,六年级信息技术上册《第一单元第2课与计算机交朋友》教案及教学反思...
- android小米手机上传图片,android 解决小米手机上选择照片路径为null的问题
- 元宇宙里的虚拟数字人:十几分钟就能制作出人体3D模型
热门文章
- 一种数据结构的封装模式
- C++项目中编译部分C的代码
- AndroidStudio安卓原生开发_UI控件_ImageView_CheckBox_RadioButton---Android原生开发工作笔记98
- k8s高可用集群_搭建高可用集群(部署master1节点初始化)---K8S_Google工作笔记0057
- ActiveMq工作笔记001---Windows10下安装ActiveMq
- SpringCloud工作笔记038---spring cloud-简单网关权限控制_直接在zuul里面做
- SpringCloud_005_Maven中的Scope详解_准备01
- springcache使用笔记001_注释驱动的 Spring cache 简单使用
- ASP.Net学习笔记014--ViewState初探3
- 使用string定义一个变量如何输出