Java.lang.RuntimeException: java.sql.SQLException: No suitable driver found

3 respostas
L

galera por favor me ajudem...

eta dando o seguinte erro...

_________________________________________________________________________________________________________________________________________
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/tcc
br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:16)
br.com.caelum.jdbc.dao.ContatoDAO.(ContatoDAO.java:15)
br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/tcc
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
br.com.caelum.jdbc.ConnectionFactory.getConnection(ConnectionFactory.java:12)
br.com.caelum.jdbc.dao.ContatoDAO.(ContatoDAO.java:15)
br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:30)
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.32 logs.
____________________________________________________________________________________________________________________________________

package br.com.caelum.agenda.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.caelum.jdbc.dao.ContatoDAO;
import br.com.caelum.jdbc.modelo.Contato;



public class AdicionaContatoServlet extends HttpServlet{
	
	protected void service(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException  {
		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.adiciona(contato);
		
		
		out.println("<html>");
		out.println("<body>");
		out.println("Contato " + contato.getNome() + "adicionado com sucesso");
		out.println("</body>");
		out.println("</html>");
		
	}

}


AdicionaContato
br.com.caelum.agenda.servlet.AdicionaContatoServlet


AdicionaContato
/adicionaContato

e o código do JDBC quando eu executo pra testa a conexão com o banco de dados...ele executa certinho...mais quando eu tento grava um contato pela web ele da esse erro....

eu jah coloquei o classpath e o driver do mysql na pasta do projeto...e dei um buildpath no driver do mysql...

me ajudem...vlw :lol:

3 Respostas

FernandoFranzini

o jar do drive tem que enviado com .war no deploy.
Coloque o jar dentro do WEB-INF/lib do projeto e tente novamente.

L

obrigado pela ajuda…

agora deu outro erro…

TTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: java.sql.SQLException: Field ‘cpf’ doesn’t have a default value

br.com.caelum.jdbc.dao.ContatoDAO.adiciona(ContatoDAO.java:31)

br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:31)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

[b]java.sql.SQLException: Field cpf doesnt have a default value

com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)

com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)

com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1021)

br.com.caelum.jdbc.dao.ContatoDAO.adiciona(ContatoDAO.java:28)

br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:31)

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.32 logs.[/b]

FernandoFranzini

lukkinhas:
obrigado pela ajuda…

agora deu outro erro…

TTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: java.sql.SQLException: Field ‘cpf’ doesn’t have a default value

br.com.caelum.jdbc.dao.ContatoDAO.adiciona(ContatoDAO.java:31)

br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:31)

javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

root cause

[b]java.sql.SQLException: Field cpf doesnt have a default value

com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)

com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)

com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)

com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)

com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)

com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)

com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)

com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1021)

br.com.caelum.jdbc.dao.ContatoDAO.adiciona(ContatoDAO.java:28)

br.com.caelum.agenda.servlet.AdicionaContatoServlet.service(AdicionaContatoServlet.java:31)

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.32 logs.[/b]


Bom agora vc tentou gravar no banco usando um INSERT que tem um campo obrigatorio no qual vc não informou valor…favor rever os campos NOT NULL.

Criado 26 de agosto de 2011
Ultima resposta 26 de ago. de 2011
Respostas 3
Participantes 2