1. Error description
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 2015 1 0 days PM 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> Please summarize function in a sentence </p> * @ Classname:student * @Description: * @Author: Youhaidong * @Date: June 10, 2015 PM 11:49:36 * */public class Student {/** * Inquiry students Basic information * @Title: Student * @Description: * @Date: June 11, 2015 a.m. 12:06:40 * @return: void * @throws */public static void Querys Tudent () {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.e Xecutequery (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 ("School Number:" +stuid+ "----" + "Name:" +stuname+ "----" + "Gender:" +stusex+ "---" + "Age:" +stuage+ "----" + "Phone:" + Stuphone);}} catch (SQLException e) {e.printstacktrace ();}} /** * * @Title: Student * @Description: * @param args * @Date: June 11, 2015 Morning 12:07:53 * @return: void * @throws */public St atic void Main (String args[]) {querystudent ();}}
3. Solutions
Due to the execution of Rs = Stat.executequery (Sql.tostring ()), SQL is empty, resulting in an error
StringBuffer sql = new StringBuffer ();
Sql.append ("SELECT * from T_stu_info");
Java.sql.SQLException:Can not issue empty query.