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. windows下cmd常用

    windows下cmd常用 shutdown -s -t 2------2秒后关机 加上-f选项意思是强制执行 shutdown -r -t 2------2秒后重启 加上-f选项意思是强制执行 lo ...

  2. RAID知识总结[转]

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://815632410.blog.51cto.com/1544685/1394306 ...

  3. BZOJ 2467: [中山市选2010]生成树 [组合计数]

    2467: [中山市选2010]生成树 Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 638  Solved: 453[Submit][Status][ ...

  4. MySQL Community Server 5.7安装详细步骤

    mysql社区版安装配置步骤较繁琐,几经搜索之后才成功安装,此文将所有的安装步骤及安装过程中遇到的问题进行了总结 1. 下载MySQL社区版     最新版下载地址:https://dev.mysql ...

  5. Redis 实践3-操作

    string常用操作 set key1  aminglinux get key1   set key1  aming //一个key对应一个value,多次赋值,会覆盖前面的value setnx k ...

  6. iOS字体名字

    上面我们提到我们需要设置字体集,在IOS系统中我们用到的字体包含一下几种 : Font Family: American Typewriter( AmericanTypewriter,American ...

  7. 基于Parallax设计HTML视差效果

    年关将至,给大家拜年. 最近时间充裕了一点,给大家介绍一个比较有意思的控件:Parallax.它可以用来实现鼠标移动时,页面上的元素也做偏移的视差效果.在一些有表现层次,布局空旷的页面上,用来做Hea ...

  8. java设计模式-----1、简单工厂模式

    简单工厂模式是属于创建型模式,又叫做静态工厂方法(Static Factory Method)模式,但不属于23种GOF设计模式之一.简单工厂模式是由一个工厂对象决定创建出哪一种产品类的实例,简单来说 ...

  9. Elasticsearch教程-从入门到精通(转载)

    转载,原文地址:http://mageedu.blog.51cto.com/4265610/1714522?utm_source=tuicool&utm_medium=referral 各位运 ...

  10. 基于netty框架的Socket传输

    一.Netty框架介绍 什么是netty?先看下百度百科的解释:         Netty是由JBOSS提供的一个java开源框架.Netty提供异步的.事件驱动的网络应用程序框架和工具,用以快速开 ...