0

Here is the code that I try to execute but it fails with an error. Can you please explain me where is my mistake

try{
    Class.forName("java.sql.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/NAgency","root","bhumika");
    Statement sta = con.createStatement();
    String Paper_ID,NOP,Price,Pages,L,q,x; Integer p=0;
    x = jTextField1.getText();
    q = "Select * From NPaper Where Paper_ID =" + x;
    ResultSet res = sta.executeQuery(q);
    if (res.first()==true){
        p=Integer.parseInt(res.getString("Paper_ID"));
        NOP = res.getString("NOP");
        Pages = res.getString("Pages");
        Price = res.getString("Price");
        L= res.getString("Lang1");
        jTextField2.setText(" "+p);
        jTextField3.setText(NOP);
        jTextField4.setText(Pages);
        jTextField5.setText(Price);
        jTextField6.setText(L);

    }else{
        JOptionPane.showMessageDialog(null, "Invalid Paper_ID");
    }
}catch (Exception e){
    JOptionPane.showMessageDialog(null, e.getMessage());
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 3
    Can you add more info on what the actual error is? And also, a working piece code would help. – BlackPearl Dec 21 '19 at 17:28
  • this is a mysql jdbc programme and i am getting the exception in interface. – bhumika verma Dec 21 '19 at 17:31
  • 4
    Please add the actual exception/Stack trace, and also the add the lines of code where the exception occurs. – BlackPearl Dec 21 '19 at 17:33
  • this is the code for show button of a form to retrieve values from sql table and i get the exception when i click on the show button despite of the fact that i have not used long anywhere. – bhumika verma Dec 21 '19 at 17:48
  • 3
    Use `e.printStackTrace()` and add the output of the entire stacktrace to your question. Your question is probably a duplicate of [ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long on connect to MySQL](https://stackoverflow.com/questions/46131295/classcastexception-java-math-biginteger-cannot-be-cast-to-java-lang-long-on-con) – Mark Rotteveel Dec 21 '19 at 18:31
  • Thank u Mark Rotteveel for referring to the above question. There was a problem with the mysql-java connector jar files. I fixed that . Aaand now it works.. Thanks for ur help. – bhumika verma Dec 22 '19 at 16:38

0 Answers0