When I execute this code, I get the error:
Exception in thread "main" java.sql.SQLException: Can not issue empty query
What is wrong with my code?
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");
}
pst.executeUpdate("");. Have you tried withpst.executeUpdate();?String sqlis parameter representing an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE which should be executed. In your case this statement is empty and because of that you see your SQLException.