Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException at adding in MySQL
    text
    copied!<p>I'm trying to add a row in my database, at the table employee. But i get an exception: </p> <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at ConnectionBD.EmployeeBD.add(EmployeeBD.java:56)` </code></pre> <p>This is my source code (EmployeeBD Class):</p> <pre><code>public void add() throws SQLException, ClassNotFoundException { 56 Employee a = ep.ReadEmployee(); 57 if (a!=null) { 58 Connection conn = null; try { Class.forName(BDConnect.DRIVER); conn = DriverManager.getConnection(BDConnect.BD_URL, BDConnect.USUARI, BDConnect.PASSWORD); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ); if (conn != null) { String sql = "SELECT * FROM employee"; ResultSet rs = stmt.executeQuery( sql ); rs.moveToInsertRow(); rs.updateString( "nif", a.getNif()); rs.updateString( "name", a.getName()); rs.updateDouble( "salary",a.getSalary()); System.out.println("Added Suscefully"); rs.insertRow(); rs.moveToCurrentRow(); } else { System.out.println("Can't get DB"); } } catch (SQLException ioe) { System.out.println(ioe); } catch(ClassNotFoundException ex) { System.out.println(ex); } } } </code></pre> <p>And the ReadEmployee() Method:</p> <pre><code>public Employee ReadEmployee() { String nif = null; String name = null; Double salary = null; int depId = 0; nif = jTextField1.getText(); name = jTextField2.getText(); salary = Double.parseDouble(jTextField3.getText()); Employee emp = new Employee(nif, name, salary, 1); if (name.equals("") || nif.equals("") || salary != null) { return emp; } else { JOptionPane.showMessageDialog(this, "Fill all TextFields", "Article warning", JOptionPane.WARNING_MESSAGE); return null; } } </code></pre> <p>Why It throws the exception? I don't know how to do it correcty!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload