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

Source: Internet
Author: User
Tags stringbuffer

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.

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.