Olá pessoal, feliz 2005…
Estou com um certo probleminha. No momento que tento adicionar dados ao BD aparece a seguinte mensagem:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
CadastroServlet.doPost(CadastroServlet.java:147)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
Apache Tomcat/5.0.28
A sintaxe da conexão no meu servlet:
try{
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”).newInstance();
connection = DriverManager.getConnection(“jdbc:microsoft:sqlserver://localhost:1433”,“sa”,“123456”);
if(connection!=null) System.out.println(“Connection Successful!”);
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}
try{
Statement statement = connection.createStatement();
sql = "INSERT INTO QUESTAO" +
"(assunto, descricao_questao, alter_correta)" +
" values ("+assunto+", "+descricao_questao+", "+alter_correta+")";
int i = statement.executeUpdate(sql);
if(i == 1){
String cod = "SELECT MAX(cod_questao) FROM QUESTAO";
for(cont=0 ; cont<4; cont++){
sql = "INSERT INTO ALTERNATIVA" +
"(alternativa, descricao_alt, cod_questao)" +
" values ("+alternativa[cont]+", "+descricao_alt[cont]+", "+cod+")";
statement.executeUpdate(sql);
}
System.out.println("Sucesso ao adicionar questão.");
res.sendRedirect("http//localhost:8080/myApp/Professor.html");
}//if
statement.close();
connection.close();
}//try
Espero q alguém possa me ajudar…
Obrigada…
Sta. Leisley