在线程" main"中获得异常java.sql.SQLException:无法发出空查询

时间:2014-08-14 21:48:51

标签: java sql

当我执行此代码时,我收到错误:

Exception in thread "main" java.sql.SQLException: Can not issue empty query

我的代码出了什么问题?

public static void main(String[] args) throws IOException,
        ClassNotFoundException, SQLException {
    // TODO Auto-generated method stub

    DataInputStream d = new DataInputStream(System.in);
    // for keyboard input
    System.out.println("Enter Employee id: ");
    int empid = Integer.parseInt(d.readLine());

    System.out.println("Enter Employee name: ");
    String empname = d.readLine();

    System.out.println("Enter Employee Salary: ");
    double empsalary = Double.parseDouble(d.readLine());

    Class.forName("com.mysql.jdbc.Driver"); // Loading MYSQL Driver
    Connection con = DriverManager.getConnection(
            "jdbc:mysql://localhost:3306/employee", "root", "admin");
    PreparedStatement pst = con
            .prepareStatement("insert into employee values(?,?,?)");
    pst.setInt(1, empid);
    pst.setString(2, empname);
    pst.setDouble(3, empsalary);
    int rowcount = pst.executeUpdate("");
    System.out.println(rowcount + "row has been insereted");

}

1 个答案:

答案 0 :(得分:3)

您从executeUpdate(String)界面拨打Statement,而不是executeUpdate()的{​​{1}}。

删除这两个引号,它应该可以正常工作