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

來源:互聯網
上載者:User

標籤:

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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.