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.