cara eu fis um sistema e nao estou conseguindo solucionar esse problema alguem pode me ajudar
package br.com.modelo;
public class Pessoa {
private long id;
private String nome;
private String endereco;
private String email;
private String telefone;
private String celular;
private String cidade;
private String bairro;
private String senha;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getCelular() {
return celular;
}
public void setCelular(String celular) {
this.celular = celular;
}
public String getCidade() {
return cidade;
}
public void setCidade(String cidade) {
this.cidade = cidade;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
public String getSenha() {
return senha;
}
public void setSenha(String senha) {
this.senha = senha;
}
}
package br.com.infra;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionFactory {
public Connection getConnection() {
try{
Class.forName("com.myql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost/CadastroPessoas","root","people");
}catch(SQLException e){
throw new RuntimeException(e);
}catch(ClassNotFoundException e){
throw new RuntimeException(e);
}
}
}
package br.com.infra;
import java.sql.SQLException;
import java.util.List;
public interface Dao {
public void adciona(T entidade) throws SQLException;
public void altera(T entidade) throws SQLException;
public void deleta(T entidade) throws SQLException;
public T lista(String pesquisa) throws SQLException;
public List<T>listaTudo()throws SQLException;
}
package br.com.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import br.com.infra.ConnectionFactory;
import br.com.infra.Dao;
import br.com.modelo.Pessoa;
public class PessoaDAO implements Dao{
//a conexão com o banco de dados
private Connection con;
public PessoaDAO() {
this.con = new ConnectionFactory().getConnection();
}
@Override
public void adciona(Pessoa entidade) throws SQLException {
String sql = "insert into pessoa(nome,endereco,email,telefone,celular,cidade,bairro,senha)value(?,?,?,?,?,?,?,?,)";
PreparedStatement stmt = null;
try{
stmt = (PreparedStatement)con.prepareStatement(sql);
stmt.setString(1, entidade.getNome());
stmt.setString(2, entidade.getEndereco());
stmt.setString(3, entidade.getEmail());
stmt.setString(4, entidade.getTelefone());
stmt.setString(5, entidade.getCelular());
stmt.setString(6, entidade.getCidade());
stmt.setString(7, entidade.getBairro());
stmt.setString(8, entidade.getSenha());
stmt.execute();
}catch(SQLException e) {
throw new RuntimeException(e);
}finally{
con.close();
stmt.close();
}
}
@Override
public void altera(Pessoa entidade) throws SQLException {
String sql = "update pessoa set";
int t = 0;
int count = 1;
if(entidade.getNome() != null && !entidade.getNome().equals("")) {
sql = sql + "nome=?";
t = 1;
}
if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "endereco=?";
t = 1;
}
if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "email=?";
t = 1;
}
if(entidade.getTelefone() != null && !entidade.getTelefone().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "telefone=?";
t = 1;
}
if(entidade.getCelular() != null && !entidade.getCelular().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "celular=?";
t = 1;
}
if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "cidade=?";
t = 1;
}
if(entidade.getBairro() != null && !entidade.getBairro().equals("")){
if(t == 1){
sql = sql + ",";
}
sql = sql + "bairro=?";
t = 1;
}
if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
if(t == 1) {
sql = sql + ",";
}
sql = sql + "senha=?";
t = 1;
}
sql = sql + "where id= ? ";
PreparedStatement stmt = null;
try{
stmt = (PreparedStatement)con.prepareStatement(sql);
if(entidade.getNome() != null && !entidade.getNome().equals("")) {
stmt.setString(count, entidade.getNome());
count++;
}
if(entidade.getEndereco() != null && !entidade.getEndereco().equals("")) {
stmt.setString(count, entidade.getEndereco());
count++;
}
if(entidade.getEmail() != null && !entidade.getEmail().equals("")) {
stmt.setString(count, entidade.getEmail());
count++;
}
if(entidade.getTelefone() != null && !entidade.getTelefone().equals("")) {
stmt.setString(count, entidade.getTelefone());
count++;
}
if(entidade.getCelular() != null && !entidade.getCelular().equals("")) {
stmt.setString(count, entidade.getCelular());
count++;
}
if(entidade.getCidade() != null && !entidade.getCidade().equals("")) {
stmt.setString(count, entidade.getCidade());
count++;
}
if(entidade.getBairro() != null && !entidade.getBairro().equals("")) {
stmt.setString(count, entidade.getBairro());
count++;
}
if(entidade.getSenha() != null && !entidade.getSenha().equals("")) {
stmt.setString(count, entidade.getSenha());
count++;
}
stmt.setLong(count, entidade.getId());
stmt.execute();
}catch(SQLException e) {
throw new RuntimeException(e);
}finally{
con.close();
stmt.close();
}
}
@Override
public void deleta(Pessoa entidade) throws SQLException {
PreparedStatement stmt = null;
try{
stmt = (PreparedStatement)con.prepareStatement("delete from pessoa where id=?");
stmt.setLong(1, entidade.getId());
stmt.execute();
}catch(SQLException e){
throw new RuntimeException(e);
}finally{
con.close();
stmt.close();
}
}
@Override
public Pessoa lista(String pesquisa) throws SQLException {
Pessoa entidade = new Pessoa();
String sql = "select * from pessoa where id = ?";
PreparedStatement stmt = null;
ResultSet rs = null;
try{
stmt = (PreparedStatement)con.prepareStatement(sql);
stmt.setLong(1, new Long(pesquisa));
rs = stmt.executeQuery();
if(rs.next()){
entidade.setId(rs.getLong("id"));
entidade.setNome(rs.getString("nome"));
entidade.setEndereco(rs.getString("endereco"));
entidade.setEmail(rs.getString("email"));
entidade.setTelefone(rs.getString("telefone"));
entidade.setCelular(rs.getString("celular"));
entidade.setCidade(rs.getString("cidade"));
entidade.setBairro(rs.getString("bairro"));
entidade.setSenha(rs.getString("senha"));
}
}catch(SQLException e) {
throw new RuntimeException(e);
}finally{
stmt.close();
rs.close();
con.close();
}
return entidade;
}
@Override
public List<Pessoa> listaTudo() throws SQLException {
List<Pessoa>pessoas = new ArrayList<Pessoa>();
String sql = "select * from pessoa";
PreparedStatement stmt = null;
ResultSet rs = null;
try{
stmt = (PreparedStatement)con.prepareStatement(sql);
rs = stmt.executeQuery();
Pessoa entidade = null;
while(rs.next()) {
entidade = new Pessoa();
entidade.setId(rs.getLong("id"));
entidade.setNome(rs.getString("nome"));
entidade.setEndereco(rs.getString("endereco"));
entidade.setEmail(rs.getString("email"));
entidade.setTelefone(rs.getString("telefone"));
entidade.setCelular(rs.getString("celular"));
entidade.setCidade(rs.getString("cidade"));
entidade.setBairro(rs.getString("bairro"));
entidade.setSenha(rs.getString("senha"));
pessoas.add(entidade);
}
}catch(SQLException e) {
throw new RuntimeException(e);
}finally{
stmt.close();
rs.close();
con.close();
}
return pessoas;
}
}
package br.com.controle;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import br.com.dao.PessoaDAO;
import br.com.modelo.Pessoa;
@WebServlet("/Pessoa")
public class PessoaServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public PessoaServlet() {
super();
}
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
PessoaDAO dao = new PessoaDAO();
String action = request.getParameter("action");
if (action != null && action.equals("gravar")) {
// buscando os parâmetros no request
Integer id = 0;
if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
id = Integer.parseInt(request.getParameter("id"));
}
String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
String email = request.getParameter("email");
String telefone = request.getParameter("telefone");
String celular = request.getParameter("celular");
String cidade = request.getParameter("cidade");
String bairro = request.getParameter("bairro");
String senha = request.getParameter("senha");
Pessoa pessoa = new Pessoa();
pessoa.setNome(nome);
pessoa.setEndereco(endereco);
pessoa.setEmail(email);
pessoa.setTelefone(telefone);
pessoa.setCelular(celular);
pessoa.setCidade(cidade);
pessoa.setBairro(bairro);
pessoa.setSenha(senha);
try {
if (id != null && id > 0) {
pessoa.setId(new Long(id));
dao.altera(pessoa);
} else {
dao.adciona(pessoa);
}
RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
dispatcher.forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (action != null && action.equals("excluir")) {
Integer id = 0;
if (request.getParameter("id") != null && !request.getParameter("id").equals("")) {
id = Integer.parseInt(request.getParameter("id"));
}
Pessoa pessoa = new Pessoa();
pessoa.setId(new Long(id));
try {
dao.deleta(pessoa);
RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
dispatcher.forward(request, response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else {
RequestDispatcher dispatcher = request.getRequestDispatcher("pessoa.jsp");
dispatcher.forward(request, response);
}
}
}
<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt” %>
Cadastro de pessoa
<button id="excluir_submit" onclick="excluir();" value="Excluir">Excluir</button>
</div>
</form><br>
<p align="center">Desenvolvido por Thiago Augusto Castelhano Teixeira</p>
Id | Nome | Endereco | telefone | celular | cidade | bairro | |
---|---|---|---|---|---|---|---|
${pessoa.id} | ${pessoa.nome} | ${pessoa.endereco} | ${pessoa.email} | ${pessoa.telefone} | ${pessoa.celular} | ${pessoa.cidade} | ${pessoa.bairro} |
o problema que esta dando é esse
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.myql.jdbc.Driver org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)root cause
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.myql.jdbc.Driver br.com.infra.ConnectionFactory.getConnection(ConnectionFactory.java:16) br.com.dao.PessoaDAO.(PessoaDAO.java:20) org.apache.jsp.pessoa_jsp._jspService(pessoa_jsp.java:87) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)root cause
java.lang.ClassNotFoundException: com.myql.jdbc.Driver org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533) java.lang.Class.forName0(Native Method) java.lang.Class.forName(Unknown Source) br.com.infra.ConnectionFactory.getConnection(ConnectionFactory.java:11) br.com.dao.PessoaDAO.(PessoaDAO.java:20) org.apache.jsp.pessoa_jsp._jspService(pessoa_jsp.java:87) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)note The full stack trace of the root cause is available in the Apache Tomcat/7.0.23 logs.
Apache Tomcat/7.0.23