0

I am getting the error:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1

try{
    Class.forName("com.mysql.cj.jdbc.Driver");

    Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/Payroll_management_system","root","Sjrj0604@#");

    String sql = "Select * from employee where E_ID=?";
    PreparedStatement pstm = conn.prepareStatement(sql);

    pstm.setInt(1,Integer.parseInt(E_ID.getText()));

    ResultSet rs = pstm.executeQuery(sql);

    if (rs.next()){
        A_ID.setText(rs.getString("A_ID"));
        DESIGNATION.setText(rs.getString("Designation"));
        E_NAME.setText(rs.getString("E_NAME"));
        PHONE.setText(rs.getString("PHONENO"));
        YOB.setText(rs.getString("YOB"));
        YEARS.setText(rs.getString("WORKINGYEARS"));
    }
    else {
        JOptionPane.showMessageDialog(null, "Record Not Found !!");
    }

    conn.close();

}catch(Exception e){ System.out.println(e);}
Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175

0 Answers0