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

  1. 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 ...

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

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

  3. java.sql.SQLException: 无法转换为内部表示 -〉java 查询oracle数据库返回错误信息

    java.sql.SQLException: 无法转换为内部表示 Query: SELECT * FROM  nontheasttycoon Parameters: []    at org.apac ...

  4. commons-dbutils:1.6 ——java.sql.SQLException: 不支持的特性

    描述:使用jdbc创建连接后,使用commons-dbutils-1.6 数据库工具类,查询报错如下:java.sql.SQLException: 不支持的特性 Query: 经过测试跟踪在commo ...

  5. 解决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. ...

  6. java.sql.SQLException: The SQL statement must not be null or empty.这个错误

    今天发现了这个错误 java.sql.SQLException: The SQL statement must not be null or empty. 并且看了些网页:综合说下这个错误. 一般都是 ...

  7. 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可以链接成功,但 ...

  8. 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 ...

  9. 【异常】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 ...

随机推荐

  1. JAVA关键字Volatile的特性

    一.简述: 关键字Volatile是JAVA虚拟机提供的最轻量级的同步机制,但是它并不容易完全被正确.完整的理解,以致于许多程序员在遇到需要处理多线程数据竞争的时候一律使用synchronized来进 ...

  2. python socket单线程通信

    注意 socket通信默认的情况下是属于阻塞形式通信,在recv与accept函数会进行阻塞 1.客户端正常退出的情况下,server端的con的通道会正常的关闭,recv直接赋值为空 2.在wind ...

  3. Selenium UI自动化解决iframe定位问题

      更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢! 原文链接:http://www.cnblogs.com/zishi/p/6735116.html 一个阴雨霏霏 ...

  4. MySQL操作的一些优化

    1.用于不要使用select * from table xxx. 需要查询哪些列就在语句中指明,一个表结构复杂时,可能会有上百列,使用*来查询时会造成很大的浪费. 2.选择合适的属性及大小    例如 ...

  5. hibernate连接MySQL配置hibernate.cfg.xml

    今天刚学完hibernate所以急着做一个hibernate的项目,有不足的请帮我改正一下.谢谢大家 <hibernate-configuration> <session-facto ...

  6. 安装RabbitMQ(一)

    RabbitMQ简介 RabbitMQ 是由 LShift 提供的一个 Advanced Message Queuing Protocol (AMQP) 的开源实现,由以高性能.健壮以及可伸缩性出名的 ...

  7. [Python Study Notes]CS架构远程访问获取信息--Client端v2.0

    更新内容: 1.增加内存信息获取 2.增加电池信息获取 3.增加磁盘信息获取 4.重新布局窗体 5.增加窗体名称 6.增加连接成功之前,不可按压 效果图: '''''''''''''''''''''' ...

  8. Go学习笔记02-源码

    第二部分 源码 基于 Go 1.4,相关文件位于 src/runtime 目录.文章忽略了 32bit 代码,有兴趣的可自行查看源码文件.为便于阅读,示例代码做过裁剪. 1. Memory Alloc ...

  9. LNMP搭建02 -- 编译安装Nginx

    [编译安装Nginx]   为了顺利安装Nginx,先安装下面这些: [CentOS 编译 nginx 前要做的事情] yum install gcc gcc-c++ kernel-devel yum ...

  10. Redis 实践2-数据结构

    alias redis-cli='/usr/local/redis/bin/redis-cli'   vi .bashrc 编辑加入  alias redis-cli='/usr/local/redi ...