Java.sql.SQLException:Can not issue empty query.

Source: Internet
Author: User



1. Description of false narrative








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. Cause of error


/**
 *
 * @Project:MySQL
 * @Title:Student.java
 * @Package:com.you.sql
 * @Description:
 * @Author:YouHaiDong
 * @Date: June 10, 2015 11:49:36 PM
 * @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>Please summarize the function in one sentence</p>
 * @ClassName:Student
 * @Description:
 * @Author:YouHaiDong
 * @Date: June 10, 2015 11:49:36 PM
 *
 */
Public class Student
{
/**
* Query student basic information
* @Title:Student
* @Description:
* @Date: June 11, 2015 12:06:40 AM
* @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("student number:"+stuId+"----"+" Name: "+stuName+"----"+" Gender: "+stuSex+"---"+" Age: "+ stuAge+"----"+"Phone: "+stuPhone";
}
}
Catch (SQLException e)
{
e.printStackTrace();
}
}

/**
*
* @Title:Student
* @Description:
* @param args
* @Date: June 11, 2015 12:07:53 AM
* @return :void
* @throws
*/
Public static void main(String args[])
{
queryStudent();
}
}

3, the solution of the method



SQL is empty because it is running RS = Stat.executequery (sql.tostring ()); Cause an error



StringBuffer sql = new StringBuffer ();
Sql.append ("SELECT * from T_stu_info");



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.






Java.sql.SQLException:Can not issue empty query.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.