public void updateQuery(String query,String name,String sub,int test,int vidp,int zad,int maks_mark,float midle_time, float midle_mark){ try { preparedStatement = connection.prepareStatement(query); //ошибка preparedStatement.setString(1,name); preparedStatement.setString(2,sub); preparedStatement.setInt(3,test); preparedStatement.setInt(4,vidp); preparedStatement.setInt(5,zad); preparedStatement.setInt(6,maks_mark); preparedStatement.setFloat(7,midle_time); preparedStatement.setFloat(8,midle_mark); preparedStatement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } } connection.updateQuery("INSERT INTO discipline(name,sub,test,vidp,zad,maks_mark,midle_time,midle_mark) VALUES(?,?,?,?,?,?,?,?)", dis, sub, test_z, vidp_z, zad_z, 0, 0, 0); //ошибка 

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

  • Show what is your connection. - Alexander Potashev
  • DBConnection connection = new DBConnection ("localhost", "root", "root", "test_lessons"); - user275180
  • NPE which line in the code indicates? connection.updateQuery? or some in this method? - Alexander Potashev
  • connection.updateQuery and preparedStatement = connection.prepareStatement (query); - user275180
  • preparedStatement = connection.prepareStatement (query); // error - is this connection defined? - Alexander Potashev

0