Senhores meu problema é esse, quando tenta abrir uma conexao com o banco ele me cai uma exception !!
Vi alguns erros desse aqui no forum porem todas as solucoes nao funfaram aqui, colocar na pasta lib do tomcat, na web-inf/lib, pelo build path, usando ip no endereco, com ou sem porta !
Alguma luz ??
[code]<?xml version="1.0" encoding="UTF-8"?>
fj21-agenda
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
<servlet>
<servlet-name>AdicionaContato</servlet-name>
<servlet-class>br.com.darros.servlet.AdicionaContatoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdicionaContato</servlet-name>
<url-pattern>/adicionaContato</url-pattern>
</servlet-mapping>
[/code]
package br.com.darros.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionFactory {
public Connection getConnection(){
System.out.println("Conectando ao Bancoo !!");
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/fj21","root","");
return con;
}catch (SQLException e){
throw new RuntimeException(e);
}
}
}
[code]package br.com.darros.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.darros.jdbc.dao.ContatoDAO;
import br.com.darros.jdbc.modelo.Contato;
@SuppressWarnings(“serial”)
public class AdicionaContatoServlet extends HttpServlet{
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String nome = request.getParameter("nome");
String email = request.getParameter("email");
String endereco = request.getParameter("endereco");
// String dataEmTexto = request.getParameter(“dataNascimento”);
// Calendar dataNascimento = null;
//
// try {
// Date date = new SimpleDateFormat(“dd/MM/yyyy”).parse(dataEmTexto);
// dataNascimento = Calendar.getInstance();
// dataNascimento.setTime(date);
// } catch (ParseException e) {
// out.println(“Erro de conversao de data”);
// return;
// }
Contato contato = new Contato();
contato.setNome(nome);
contato.setEmail(email);
contato.setEndereco(endereco);
// contato.setDataNascimento(dataNascimento);
ContatoDAO dao = new ContatoDAO();
dao.Adiciona(contato);
out.println("<html>");
out.println("<body>");
out.println("Contato " + contato.getNome() + " adicionado com sucesso !");
out.println("</body>");
out.println("</html>");
}
}
[/code]
Nov 09, 2011 10:29:19 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [AdicionaContato] in context with path [/fj21-agenda] threw exception
java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
at br.com.darros.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:15)
at br.com.darros.jdbc.dao.ContatoDAO.<init>(ContatoDAO.java:20)
at br.com.darros.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:44)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/fj21
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at br.com.darros.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)
... 19 more