[code]package br.com.controle.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.DAO.ContatoDAO;
import br.com.model.*;
public class OiMundo extends HttpServlet {
protected void processRequest(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
String email = request.getParameter("email");
Contato contato = new Contato();
contato.setNome(nome);
contato.setEndereco(endereco);
contato.setEmail(email);
ContatoDAO dao = new ContatoDAO();
dao.doInsert(contato);
out.println("<html>");
out.println("<body>");
out.println("Contato " + contato.getNome() );
out.println("</br>");
out.println("Endereco " + contato.getEndereco() );
out.println("</br>");
out.println("E-mail :" + contato.getEmail() );
out.println("</br>");
out.println("adicionado com sucesso");
out.println("</body>");
out.println("</html>");
}
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException {
processRequest(request, response);
}
}
[/code]
minha servlet
[code]package br.com.DAO;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Connection;
import javax.swing.JOptionPane;
import com.sun.org.apache.bcel.internal.generic.RETURN;
public class Conexao {
private static String Driver = “com.mysql.jdbc.Driver”;
private static String URL=“jdbc:mysql://localhost/Cadastro”;
private static String senha=“tessaiga”;
private static String login=“root”;
public static Connection getConnection()
{
try {
Class.forName(Driver);
return DriverManager.getConnection(URL,login,senha);
}
catch (SQLException e)
{
JOptionPane.showMessageDialog(null,“erro de sql”);
return null;
}
catch (ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,“ploblemas com parametro de conexao”);
return null;
}
}
}
[/code]
minha classe de conexao
package br.com.DAO;
import br.com.model.*;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.swing.JOptionPane;
public class ContatoDAO {
public void doInsert(Contato contato)
{
try {
Connection con = Conexao.getConnection();
String sql = "insert into dado values(?,?,?)";
PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1,contato.getNome());
stmt.setString(2,contato.getEmail());
stmt.setString(3,contato.getEndereco());
stmt.execute();
stmt.close();
}
catch (SQLException e)
{
JOptionPane.showMessageDialog(null,
"Erro desconhecido, cadastro nao realizado");
}
}}
da erro de driver de mysql mais so
que ja deste a conexao com outras classes
mais nunca usei com servlet
e ficar dando este errro doido que nao sei o que quer dizer
pq ja coloquei o driver do mysql
e da errro de ClassNotFoundException
se puderem me ajuda agradeço
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
br.com.DAO.ContatoDAO.doInsert(ContatoDAO.java:18)
br.com.controle.servlet.OiMundo.processRequest(OiMundo.java:29)
br.com.controle.servlet.OiMundo.doGet(OiMundo.java:46)
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.26 logs.