Eu tu tentando fazer um crud mais quando eu coloco pra salvar não salva…
Alguem pode dá uma olhada??
AlunoDAO:
[code]package com.projeto.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.projeto.jdbc.;
import com.projeto.view.;
public class AlunoDAO {
Connection connection;
public AlunoDAO() {
this.connection = new FabricaDeConexao().getConnection();
}
public boolean adicionarAluno(AlunoBean aluno) {
String sql = "insert into cadastroaluno (matricula, nome, email, rg, fone, endereco, email_responsavel, diretor_turma)VALUES (?,?,?,?,?,?,?,?)";
try {
PreparedStatement stmt = this.connection.prepareStatement(sql);
stmt.setInt(1, aluno.getMatricula());
stmt.setString(2, aluno.getNome());
stmt.setString(3, aluno.getEmail());
stmt.setInt(4, aluno.getRg());
stmt.setString(5, aluno.getFone());
stmt.setString(6, aluno.getEndereco());
stmt.setString(7, aluno.getEmail_responsavel());
stmt.setString(8, aluno.getDiretor_turma());
ResultSet rs = stmt.executeQuery();
stmt.execute();
// verifica se existe retorno na consulta
if (rs.next()) {
stmt.close();
return true;
} else {
stmt.close();
return false;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
} [/code]
Fabrica de Conexao:
[code]package com.projeto.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class FabricaDeConexao {
public Connection getConnection() {
System.out.println(“Conectando ao Banco de Dados…”);
String stringDeConexao = "jdbc:mysql://localhost/PDT";
String user = "root";
String pass = "";
try {
return DriverManager.getConnection(stringDeConexao, user, pass);
} catch (SQLException e) {
throw new RuntimeException(e
+ "\nNAO FOI POSSIVEL CONECTAR NO BANCO DE DADOS");
}
}
}[/code]
Bean:
[code]package com.projeto.view;
import javax.faces.event.ActionEvent;
import com.projeto.dao.AlunoDAO;
public class AlunoBean extends AlunoDAO {
String nome;
int matricula;
String email;
int rg;
String fone;
String endereco;
String nome_responsavel;
String email_responsavel;
String Diretor_turma;
public int getMatricula() {
return matricula;
}
public void setMatricula(int matricula) {
this.matricula = matricula;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public int getRg() {
return rg;
}
public void setRg(int rg) {
this.rg = rg;
}
public String getFone() {
return fone;
}
public void setFone(String fone) {
this.fone = fone;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getNome_responsavel() {
return nome_responsavel;
}
public void setNome_responsavel(String nome_responsavel) {
this.nome_responsavel = nome_responsavel;
}
public String getEmail_responsavel() {
return email_responsavel;
}
public void setEmail_responsavel(String email_responsavel) {
this.email_responsavel = email_responsavel;
}
public String getDiretor_turma() {
return Diretor_turma;
}
public void setDiretor_turma(String diretor_turma) {
Diretor_turma = diretor_turma;
}
public String getTelefone_responsavel() {
return telefone_responsavel;
}
public void setTelefone_responsavel(String telefone_responsavel) {
this.telefone_responsavel = telefone_responsavel;
}
String telefone_responsavel;
public void enviar(ActionEvent event) {
this.setNome(this.getNome().toUpperCase());
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public AlunoBean() {
}
}[/code]
JSF: //Não coloquei todos os campos do banco coloquei só MATRICULA, NOME E E-MAIL
[code]<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib prefix=“f” uri=“http://java.sun.com/jsf/core”%>
<%@ taglib prefix=“h” uri=“http://java.sun.com/jsf/html”%>
[/code]
Obrigado!