执行此代码时,出现错误:
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");
}
您正在executeUpdate(String)
从Statement
界面而不是executeUpdate()
从进行呼叫PreparedStatement
。
删除两个引号,它应该工作
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句