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.的更多相关文章
- java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
1.错误描写叙述 java.sql.SQLException: Can not issue data manipulation statements with executeQuery(). at c ...
- java.sql.SQLException: Can not issue executeUpdate() for SELECTs
未处理的多个select语句 解决方法就是:查看有没有用了同一个连接来处理多个SQL语句!
- java.sql.SQLException: 无法转换为内部表示 -〉java 查询oracle数据库返回错误信息
java.sql.SQLException: 无法转换为内部表示 Query: SELECT * FROM nontheasttycoon Parameters: [] at org.apac ...
- commons-dbutils:1.6 ——java.sql.SQLException: 不支持的特性
描述:使用jdbc创建连接后,使用commons-dbutils-1.6 数据库工具类,查询报错如下:java.sql.SQLException: 不支持的特性 Query: 经过测试跟踪在commo ...
- 解决java.sql.SQLException: ORA-01789: query block has incorrect number of result columns
java.sql.SQLException: ORA-01789: query block has incorrect number of result columns at oracle.jdbc. ...
- java.sql.SQLException: The SQL statement must not be null or empty.这个错误
今天发现了这个错误 java.sql.SQLException: The SQL statement must not be null or empty. 并且看了些网页:综合说下这个错误. 一般都是 ...
- presto——java.sql.SQLException: Error executing query与javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?异常问题
使用presto的时候以mysql为presto的数据源 安装的presto是0.95版本:使用的presto-jdbc是0.202的,这里使用jdbc去访问时候,connection可以链接成功,但 ...
- java.sql.SQLException: Column count doesn't match value count at row 1 Query: insert into category values(null,?,?,?) Parameters: [1111111, 1111, 软件]
java.sql.SQLException 问题: java.sql.SQLException: Column count doesn't match value count at row 1 Que ...
- 【异常】java.sql.SQLException: Could not retrieve transaction read-only status from server Query
1 详细异常 java.sql.SQLException: Could not retrieve transaction read-only status , ], [ChargingOrderRea ...
随机推荐
- FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:javax.jdo.JDODataStoreException: An exception was thrown while adding/validating class(es) :
在hive命令行创建表时报错: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. ...
- 数据库MySQL的基本操作
1.MySQL数据库的安装: CentOS6上mysql服务端和客户端的安装和启动: #使用yum安装mysql数据库的服务端和客户端 yum install -y mysql mysql-serve ...
- JVM学习(二)
Java中的内存的划分可以用下图来表示: 程序计数器:每一个线程都有一个程序计数器,记录需要执行的下一条指令. HootSpot虚拟机中,不区分虚拟机栈和本地方法栈,统一称为栈.虚拟机栈和本地方法栈也 ...
- POJ2396 Budget [有源汇上下界可行流]
POJ2396 Budget 题意:n*m的非负整数矩阵,给出每行每列的和,以及一些约束关系x,y,>=<,val,表示格子(x,y)的值与val的关系,0代表整行/列都有这个关系,求判断 ...
- CodeChef Chef and Churu [分块]
题意: 单点修改$a$ 询问$a$的区间和$f$的区间和 原来普通计算机是这道题改编的吧... 对$f$分块,预处理$c[i][j]$为块i中$a_j$出现几次,$O(NH(N))$,只要每个块差分加 ...
- Linux C 一个简单的线程池程序设计
最近在学习linux下的编程,刚开始接触感觉有点复杂,今天把线程里比较重要的线程池程序重新理解梳理一下. 实现功能:创建一个线程池,该线程池包含若干个线程,以及一个任务队列,当有新的任务出现时,如果任 ...
- django-rest-framework快速入门
前言:第一次接触django-rest-framework是在实习的时候.当时也不懂,看到视图用类方法写的感觉很牛逼的样子.因为官网是英文的,这对我的学习还是有一点的阻力的,所以当时也没怎么学.真是太 ...
- cnpm,vue等命令不识别的问题废人解决方案
关于安装的cnpm,vue等不识别的问题 我想了很久然后再网上看了一些教程发现添加系统变量Path没什么用 我就在用户变量里面添加的,完美解决问题 在我的电脑右键->属性->高级系统设置- ...
- php 数组变成树状型结构
<? php $stime = microtime(true); $nodes = [ ['id' = > 1, 'pid' = > 0, 'name' = > 'a'], [ ...
- Netty ByteBuf梳理
我们知道,网络数据的基本单位总是字节.Java NIO提供了ByteBuffer作为它的字节容器,但是这个类使用起来过于复杂,而且也有些繁琐. Netty的ByteBuffer替代品是ByteBuf, ...