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. spring之setter注入

    setter注入分为2种 第一:普通属性注入 <bean id="userAction" class="com.xx.action.UserAction" ...

  2. MySQL笔记-语句的执行顺序

    在一次查询线上问题时发现有以下两条同样的SQL,执行后数据的顺序不一样: SELECT * FROM nns_assists_item AS asset WHERE asset.nns_assist_ ...

  3. 夏令营提高班上午上机测试 Day 4 解题报告

    我要是没记错的话,今天的题难度算挺适中的. *标程来自高天宇哥哥 T1:小G的字符串 题目描述 有一天,小 L 给小 G 出了这样一道题:生成一个长度为 n 的.全由小写英文字母构成的字符串,只能使用 ...

  4. POJ 3182 The Grove [DP(spfa) 射线法]

    题意: 给一个地图,给定起点和一块连续图形,走一圈围住这个图形求最小步数 本来是要做课件上一道$CF$题,先做一个简化版 只要保证图形有一个点在走出的多边形内就可以了 $hzc:$动态化静态的思想,假 ...

  5. BZOJ 3238: [Ahoi2013]差异 [后缀自动机]

    3238: [Ahoi2013]差异 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 2512  Solved: 1140[Submit][Status ...

  6. vue 使用Jade模板写html,stylus写css

    vue 使用Jade模板写html,stylus写css 日常工作都是使用vue开发页面和webApp,写的多了就想偷懒简化各种书写方式,所以使用了jade写html,stylus写css,省了很多的 ...

  7. linear-grident的属性和使用

    css3新增Gradient属性,用来增加渐变的效果,渐变分为线性渐变 linear-grident 和 径向渐变 radial-grident,这篇文章主要介绍线性渐变linear-grident ...

  8. laravel服务容器-----深入理解控制反转(IoC)和依赖注入(DI)

    首先大家想一想什么是容器,字面意思就是盛放东西的东西,常见的变量,对象属性都是容器,一个容器能够装什么东西,完全在于你对这个容器的定义.有的容器不仅仅只是存文本,变量,而是对象,属性,那么我们通过这种 ...

  9. 音乐之声——midi制作原理

    实际发出声音需要4项必备的条件 1 发生的装置 Sequencer     把sequencer想成CD播放机 (plays) 2 要演奏的乐曲 Sequence     sequence就好像是单曲 ...

  10. JaveScript函数(JS知识点归纳六)

    1.函数的基本使用 a)作用:代码的复用,灵活性比较强 b)声明方式:function 名 (形参){函数体} c)调用: 名(实参); d)封装函数--书写一个函数的结构,而且放入一些功能,在需要使 ...