使用glassfish4.1服务器插入值时,jdbc nullpointerexception

时间:2018-08-18 13:36:01

标签: java jsp jdbc nullpointerexception glassfish-4

我有类似的项目,但是第一次没有错误。我只是按照他们的语法,插入值时突然以前的项目弹出错误,并且我对此代码有类似的问题,空指针异常,没有密码。可以肯定的是,我的Calculate.java不是它的原因。

picture of JDBC databses

private void initializeJDBC() {
   try {
  // Declare driver and connection string
  String driver = "org.apache.derby.jdbc.ClientDriver";
  String connectionString = "jdbc:derby://localhost:1527/Grade";

  // Load the Oracle JDBC Thin driver
  Class.forName(driver);
  System.out.println("Driver " + driver + " loaded");

  // Connect to the sample database
  Connection conn = DriverManager.getConnection
    (connectionString);
  System.out.println("Database " + connectionString +
    " connected");


  pstmt = conn.prepareStatement("insert into UNTITLED " +
    "(NAME, GENDER, SUBJECT, QUIZ, ASSIGNMENT, TEST, PROJECT, FINAL,     GRADE) values (?, ?, ?, ?, ?, ?, ?, ?,  ?)");
FINALEXAM, GRADE) values (?, ?, ?, ?, ?, ?, ?, ?,  ?)");
   }
    catch (Exception ex) {
  System.out.println(ex);
    } 
        }

public void storeGrade(Calculate cal) throws SQLException 
{
pstmt.setString(1, cal.getName());
pstmt.setString(2, cal.getGender());
pstmt.setString(3, cal.getSubject());
pstmt.setString(4, String.valueOf(cal.getQuiz()));
pstmt.setString(5, String.valueOf(cal.getAssignment()) );
pstmt.setString(6,String.valueOf(cal.getTest()) );
pstmt.setString(7, String.valueOf(cal.getProject()));
pstmt.setString(8,String.valueOf(cal.getFinalexam()));
pstmt.setString(9, cal.getGrade());
pstmt.executeUpdate();

}


 <jsp:useBean id = "cal" 
class = "my.unikl.com.Calculate" scope = "session"></jsp:useBean>

 <jsp:useBean id = "de" 
 class = "my.unikl.com.DetailsStore" scope = "application"></jsp:useBean>
<html>
  <body>

     <%    

   de.storeGrade(cal);
    out.println(cal.getName()+" "+

        "is now registered in the database");
  out.close();
%>

</body>

0 个答案:

没有答案