Pessoal está dando um erro qdo eu mando inserir um valor no banco acho que é alguma coisa com minha classe de conexão, alguém pode me ajudar?
Conexão:
package ConexaoBD;
import java.sql.*;
public class Conexao {
public static Connection con;
public static Statement stm;
public static ResultSet rs;
private static String res = "";
public static void conexao() {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/portal?zeroDateTimeBehavior=convertToNull","portal","alltec");
stm = con.createStatement();
res = "Conexão efetuada com sucesso";
} catch (Exception e) {
res = "não foi possível conectar ao banco" + e.getMessage();
}
}
}
SERVLET:
package Servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ConexaoBD.Conexao;
import Data.Data;
public class CqaCadastraAlteraExclui extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=ISO-8859-1");
PrintWriter out = response.getWriter();
String nomeSession = null;
String acao = null;
nomeSession = (String) request.getParameter("nomeSession");
acao = (String) request.getParameter("acao");
if (acao.equals("cadastra") || acao.equals("alterar") || acao.equals("excluir") || acao.equals("consultar") || acao.equals("alterar")) {
new Conexao();
String dt = Data.data_hora();
}
if (acao.equals("cadastra")) {
Conexao.stm.executeUpdate("insert into cqa (criador) values('"+nomeSession+"')");
Conexao.con.close();
response.sendRedirect("cqa/cqaDefineFluxo.jsp?cadastro=OK&criadorCqa="+nomeSession+"");
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
try {
processRequest(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
ERRO:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
Servlets.CqaCadastraAlteraExclui.processRequest(CqaCadastraAlteraExclui.java:35)
Servlets.CqaCadastraAlteraExclui.doGet(CqaCadastraAlteraExclui.java:42)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.
type Exception report