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 ...
随机推荐
- spring boot 中实现兼容不同的请求类型的方法。
比如一个接口,既想实现请求参数是application/json,又想实现form提交,改怎么做呢?用postman去测试,发现不可能做到两全其美. 我有一个方法,就是不用requestbody,也可 ...
- dl在不同浏览器下显示不同
dl在chrome浏览器和在火狐浏览器下的默认样式是不一样的,解决方法将dl换成ol或ul样式就正常了.
- C# Ioc ASP.NET MVC Dependency Injection
ASP.NET MVC Dependency Injection 同志们,非常快速的Ioc注册接口和注入Mvc Controller,步骤如下: 安装Unity.Mvc NuGet Package 在 ...
- 随机切换IP和UA
在爬虫爬取过程中,网站会根据我们的IP和UA去确认到底是浏览器操作还是爬虫在操作,所以,为了让爬虫不被网站禁止,随机切换Ip 和UA是很重要的,因为这个类在各个爬虫中经常要用到,所以可以自已维护一份随 ...
- python3中,os.path模块下常用的用法总结
abspath basename dirname exists getatime getctime getmtime getsize isabs isdir isfile islink ismount ...
- iOS-image图片压缩
///压缩图片 + (NSData *)imageCompressToData:(UIImage *)image{ NSData *data=UIImageJPEGRepresentation(ima ...
- Go笔记-标准库的介绍
[unsafe]包含了一些打破Go语言“类型安全”的命令,一般的程序中不会被使用,可用在C/C++程序的调用中 [syscall]底层的外部包,提供了操作系统底层调用的基本接口 [os/exec]提供 ...
- Maven pom.xml简单归结
Maven pom.xml文件解释 请确保有相关的maven知识,包括Maven安装.Maven settings.xml解读.本文对POM的一些属性作一些摘录,详细的配置可查看此篇转载文章" ...
- How to fix “HTTP Status Code 505 – HTTP Version Not Supported” error?--转
http://dotnetstock.com/technical/http-status-code-505-http-version-not-supported/ The reason for the ...
- POJ [P2289] Jamie's Contact Groups
二分+二分图多重匹配 辣鸡ACM式读入 对于这种奇葩的读入方法,还是老老实实的用scanf吧 #include <iostream> #include <cstdio> #in ...