0

i'm trying to get some values from jTable (the values in JTable are from MySQL) to JTextField.

I got "Null Pointer Exception" after selecting the row.

After i put Line BreakPoint i see that row number is get. But at the rs=ppst.executeQuery(); line it shows me NullPointerException.

What's wrong?

here is my code:

private void jTableStudentaiMouseClicked(java.awt.event.MouseEvent evt) {                                             

       try{
            int row = jTableStudentai.getSelectedRow();
            String Table_click = (jTableStudentai.getModel().getValueAt(row, 0).toString());

            String sql = "select * from studentas inner join grupė on studentas.GrupėsID=grupė.GrupėsID where StudentoNr ='"+Table_click+"'";
       ppst=co.prepareStatement(sql);
       rs=ppst.executeQuery();
       if(rs.next()){

       String add0 = rs.getString("StudentoNr");
       jTextField1.setText(add0);
       String add1 = rs.getString("Vardas");
       jTextFieldVardas.setText(add1);
       String add2 = rs.getString("Pavardė");
       jTextFieldPavarde.setText(add2);
       String add3 = rs.getString("EPaštas");
       jTextFieldPastas.setText(add3);
       }

       }catch(Exception e){

           JOptionPane.showMessageDialog(null, e);

       }`

1 Answers1

0

Well, if prepareStatement(sql) is unable to produce a prepared statement, then it might easily have returned null; that's easy to check with a breakpoint, and maybe with looking for a stacktrace. You have no space between "student" and "as" in the sql posted, that looks like a potential problem...

arcy
  • 12,845
  • 12
  • 58
  • 103
  • thx for your answer, but it's lithuanian language :) so studentas means student :) – Arnas Arnelis Feb 08 '16 at 19:34
  • LOL - hadn't thought of that. Nevertheless, I would check to ensure that you're getting an object back from `prepareStatement()`. – arcy Feb 08 '16 at 23:37