Em minha aplicação para deskotp minhas classes estão cadastrando, alterando e excluindo..
Mas a do Funcionário está só salvando no banco de dados. Na consulta do funcionário, a coluna "Matrícula" está aparecendo os dados como "null"
Não sei o que tem de errado já que usei um padrão nas minhas classes e todas funcionaram menos essa do funcionário.
Erro:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "null"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at br.com.telas.CadFuncionario$3.mouseClicked(CadFuncionario.java:302)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.WaitDispatchSupport$2.run(Unknown Source)
at java.awt.WaitDispatchSupport$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(Unknown Source)
at java.awt.Dialog.show(Unknown Source)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at br.com.telas.Principal$2.actionPerformed(Principal.java:125)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
package br.com.telas;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import java.awt.Font;
import javax.swing.SwingConstants;
import javax.swing.JPasswordField;
import javax.swing.border.LineBorder;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.text.MaskFormatter;
import java.awt.Button;
import javax.swing.ListSelectionModel;
import br.com.bean.Funcionario;
import br.com.dao.FuncionarioDao;
import br.com.exception.DaoException;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.JFormattedTextField;
public class CadFuncionario extends JDialog {
final JPanel lista = new JPanel();
final JPanel formulario = new JPanel();
private FuncionarioDao funcDao = new FuncionarioDao();
private static final long serialVersionUID = 1L;
private JPasswordField passwordField;
private JPasswordField passwordField_1;
private JTable table;
private JTextField textField;
private JTextField textField_2;
private JFormattedTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;
private JFormattedTextField textField_1;
public CadFuncionario() throws DaoException {
setModal(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setTitle("Cadastro de Funcion\u00E1rios");
setIconImage(Toolkit.getDefaultToolkit().getImage(CadFuncionario.class.getResource("/br/com/images/logo_transp.png")));
int width = 800;
int height =600;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width-width)/2;
int y = (screen.height-height)/3;
setBounds(x,y,width,height);
getContentPane().setLayout(null);
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(UIManager.getColor("Button.background"));
buttonPanel.setBounds(0, 0, 152, 562);
getContentPane().add(buttonPanel);
buttonPanel.setLayout(null);
formulario.setBounds(152, 0, 632, 562);
getContentPane().add(formulario);
formulario.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(new TitledBorder(new LineBorder(new Color(0, 0, 0)), "", TitledBorder.LEADING, TitledBorder.TOP, null, null), "Dados pessoais", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
panel.setLayout(null);
panel.setBounds(21, 35, 590, 288);
formulario.add(panel);
passwordField = new JPasswordField();
passwordField.setBounds(333, 205, 94, 20);
panel.add(passwordField);
JLabel lblConfirmarASenha = new JLabel("Confirmar a senha:");
lblConfirmarASenha.setHorizontalAlignment(SwingConstants.RIGHT);
lblConfirmarASenha.setFont(new Font("Arial Black", Font.PLAIN, 12));
lblConfirmarASenha.setBounds(196, 205, 127, 18);
panel.add(lblConfirmarASenha);
passwordField_1 = new JPasswordField();
passwordField_1.setBounds(92, 205, 94, 20);
panel.add(passwordField_1);
JLabel label_2 = new JLabel("Senha:");
label_2.setHorizontalAlignment(SwingConstants.RIGHT);
label_2.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_2.setBounds(12, 205, 70, 18);
panel.add(label_2);
JLabel label_3 = new JLabel("Login:");
label_3.setHorizontalAlignment(SwingConstants.RIGHT);
label_3.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_3.setBounds(12, 176, 70, 18);
panel.add(label_3);
JLabel label_4 = new JLabel("Profissão:");
label_4.setHorizontalAlignment(SwingConstants.RIGHT);
label_4.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_4.setBounds(12, 60, 70, 18);
panel.add(label_4);
JLabel label_5 = new JLabel("Nome:");
label_5.setHorizontalAlignment(SwingConstants.RIGHT);
label_5.setFont(new Font("Arial Black", Font.PLAIN, 12));
label_5.setBounds(12, 31, 70, 18);
panel.add(label_5);
JButton button = new JButton("Salvar");
button.setBounds(491, 254, 89, 23);
panel.add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String senha = new String(passwordField.getPassword());
String cSenha = new String(passwordField_1.getPassword());
if(senha.equals(cSenha)){
Funcionario obj = new Funcionario();
obj.setProfissaoFunc(textField_2.getText());
obj.setLogin(textField_4.getText());
obj.setNomeFunc(textField.getText());
obj.setTelFunc(textField_3.getText());
obj.setSalarioFunc(Double.parseDouble(textField_1.getText()));
obj.setSenha(cSenha);
FuncionarioDao objDAO = new FuncionarioDao();
//Integer matr = Integer.parseInt(textField_5.getText());
int matri = 0;
try {
if(textField_5.getText().equals("")){
objDAO.inserirFuncionarios(obj, matri);
JOptionPane.showMessageDialog(null, formulario, "Dados salvos com sucesso!" +
"Número do Funcionário: ", matri); //Como mostrar o número do Funcionário?
}else{
Integer matr = Integer.parseInt(textField_5.getText());
obj.setNumFunc(matr);
objDAO.atualizarFuncionario(obj);
JOptionPane.showMessageDialog(formulario, "Dados atualizados com sucesso!");
}
atualizaLista(table);
} catch (DaoException e) {
e.printStackTrace();
}
}else{
JOptionPane.showMessageDialog(formulario, "Os campos 'senha' e 'confirme a senha' devem ter o mesmo conteúdo!");
}
}
});
JButton button_1 = new JButton("Limpar");
button_1.setBounds(392, 254, 89, 23);
panel.add(button_1);
button_1.setToolTipText("Limpar os campos");
button_1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
limpaFormulario();
}
});
textField = new JTextField();
textField.setBounds(92, 31, 335, 20);
panel.add(textField);
textField.setColumns(10);
textField_2 = new JTextField();
textField_2.setBounds(92, 60, 127, 20);
panel.add(textField_2);
textField_2.setColumns(10);
MaskFormatter mascraFormat2 = null;
try {
mascraFormat2 = new MaskFormatter("(##)####-####");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
textField_3 = new JFormattedTextField(mascraFormat2);
textField_3.setBounds(92, 91, 127, 20);
panel.add(textField_3);
textField_3.setColumns(10);
textField_4 = new JTextField();
textField_4.setBounds(92, 174, 190, 20);
panel.add(textField_4);
textField_4.setColumns(10);
textField_5 = new JTextField();
textField_5.setVisible(false);
textField_5.setText("");
panel.add(textField_5);
JLabel lblTel = new JLabel("Tel.:");
lblTel.setFont(new Font("Arial Black", Font.PLAIN, 12));
lblTel.setBounds(50, 93, 60, 14);
panel.add(lblTel);
JLabel lblSalrio = new JLabel("Sal\u00E1rio:");
lblSalrio.setFont(new Font("Arial Black", Font.PLAIN, 12));
lblSalrio.setBounds(236, 63, 70, 14);
panel.add(lblSalrio);
/* MaskFormatter mascraFormat4 = null;
try {
mascraFormat4 = new MaskFormatter("R$####,##");
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}*/
textField_1 = new JFormattedTextField();
textField_1.setBounds(310, 60, 117, 20);
panel.add(textField_1);
textField_1.setColumns(10);
JButton btnVoltar = new JButton("Voltar");
btnVoltar.setBounds(21, 340, 89, 23);
formulario.add(btnVoltar);
lista.setBounds(152, 0, 632, 562);
getContentPane().add(lista);
lista.setLayout(null);
JLabel lblFuncionriosCadastrados = new JLabel("Funcion\u00E1rios Cadastrados");
lblFuncionriosCadastrados.setFont(new Font("Kalinga", Font.BOLD, 16));
lblFuncionriosCadastrados.setHorizontalAlignment(SwingConstants.CENTER);
lblFuncionriosCadastrados.setBackground(Color.WHITE);
lblFuncionriosCadastrados.setBounds(10, 11, 612, 29);
lista.add(lblFuncionriosCadastrados);
Button Novo = new Button("Adicionar");
Novo.setBounds(10, 530, 70, 22);
lista.add(Novo);
lista.setVisible(true);
table = new JTable();
table.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent arg0) {
int linha = table.getSelectedRow();
int coluna = table.getSelectedColumn();
String matricula = (String) table.getValueAt(linha,0);
Integer mat = Integer.parseInt(matricula);
if(coluna == 4){
int opcao;
opcao = JOptionPane.showConfirmDialog(null,"Deseja excluir o registro de matricula: "+ matricula ,"Cuidado!!",JOptionPane.YES_NO_OPTION);
if(opcao == JOptionPane.YES_OPTION){
try {
funcDao.excluirFuncionarios(mat);
atualizaLista(table);
} catch (DaoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JOptionPane.showMessageDialog(null, "Dados excluidos com sucesso!");
}
}
if (coluna == 3){
Funcionario objFunc = new Funcionario();
try {
objFunc = funcDao.consultarFuncionarioID(mat);
atualizaFormulario(objFunc);
} catch (DaoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setModel(new DefaultTableModel(
new Object[][] {
},
new String[] {
"Matr\u00EDcula", "Nome", "Telefone", "Editar","Excluir"
}
)
{
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int col)
{
return false;
}
}
);
table.getColumnModel().getColumn(0).setPreferredWidth(55);
table.getColumnModel().getColumn(0).setMinWidth(55);
table.getColumnModel().getColumn(1).setPreferredWidth(250);
table.getColumnModel().getColumn(1).setMinWidth(250);
table.getColumnModel().getColumn(2).setPreferredWidth(150);
table.getColumnModel().getColumn(2).setMinWidth(150);
table.setBounds(39, 175, 530, 232);
atualizaLista(table);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(0, 51, 622, 473);
lista.add(scrollPane);
scrollPane.setViewportView(table);
Novo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lista.setVisible(false);
formulario.setVisible(true);
limpaFormulario();
try {
atualizaLista(table);
} catch (DaoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
formulario.setVisible(false);
btnVoltar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lista.setVisible(true);
formulario.setVisible(false);
}
});
}
public void atualizaLista(JTable lista) throws DaoException{
DefaultTableModel dtm = (DefaultTableModel) table.getModel();
ImageIcon editar = new ImageIcon(CadFuncionario.class.getResource("/br/com/images/editar.gif"));
ImageIcon excluir = new ImageIcon(CadFuncionario.class.getResource("/br/com/images/icon_excluir.png"));
TableColumnModel columnModel = table.getColumnModel();
JTableRenderer renderer = new JTableRenderer();
JTableRenderer renderer1 = new JTableRenderer();
renderer.setValue(editar);
renderer.setHorizontalAlignment(JLabel.CENTER);
renderer.setToolTipText("Editar");
columnModel.getColumn(3).setCellRenderer(renderer);
renderer1.setValue(excluir);
renderer1.setHorizontalAlignment(JLabel.CENTER);
renderer1.setToolTipText("Excluir");
columnModel.getColumn(4).setCellRenderer(renderer1);
dtm.setRowCount(0);
List<Funcionario> listaFunc = new ArrayList<Funcionario>();
listaFunc = funcDao.consultarFuncionarios();
String dados[] = new String[3];
for (Funcionario obj : listaFunc) {
dados[0] = String.valueOf(obj.getNumFunc());
dados[1] = obj.getNomeFunc();
dados[2] = obj.getTelFunc();
((DefaultTableModel) table.getModel()).addRow(dados);
}
table.repaint();
}
public class JTableRenderer extends DefaultTableCellRenderer {
private static final long serialVersionUID = 1L;
protected void setValue(Object value) {
if (value instanceof ImageIcon) {
if (value != null) {
ImageIcon d = (ImageIcon) value;
setIcon(d);
}
} else {
super.setValue(value);
}
}
}
public void atualizaFormulario(Funcionario objFunc){
textField_3.setText(objFunc.getTelFunc());
textField_2.setText(objFunc.getProfissaoFunc());
textField_4.setText(objFunc.getLogin());
textField.setText(objFunc.getNomeFunc());
textField_1.setText(objFunc.getSalarioFunc().toString());
passwordField.setText("");
passwordField_1.setText("");
Integer matr = objFunc.getNumFunc();
textField_5.setText(matr.toString());
lista.setVisible(false);
formulario.setVisible(true);
}
public void limpaFormulario(){
textField.setText("");
textField_2.setText("");
textField_3.setText("");
textField_4.setText("");
textField_5.setText("");
passwordField.setText("");
passwordField_1.setText("");
}
}
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 javax.swing.JOptionPane;
import br.com.exception.DaoException;
import br.com.util.DbUtil;
import br.com.bean.Funcionario;
public class FuncionarioDao {
private static final String EXCLUIR_FUNCIONARIO =
"delete from tbfuncionario where numFunc = ?";
private static final String INSERIR_FUNCIONARIO =
"insert into tbfuncionario(nomeFunc, telFunc, profissaoFunc, "+
"login_funcionario, senha_funcionario, salarioFunc) " +
"values (?,?,?,?,?,?)";
private static final String ATUALIZAR_FUNCIONARIO =
"update tbfuncionario set " +
"nomeFunc = ?, " +
"telFunc = ?, " +
"profissaoFunc = ?, " +
"login_funcionario = ?, " +
"senha_funcionario = ?, " +
"salarioFunc = ? " +
"where numFunc = ? ";
private static final String ATUALIZAR_FUNCIONARIO_FOLHA =
"update tbfuncionario set " +
"nomeFunc = ?, " +
//"telFunc = ?, " +
"profissaoFunc = ?, " +
"salarioFunc = ?, " +
//"login_funcionario = ?, " +
//"senha_funcionario = ? " +
"where numFunc = ? ";
private static final String VALIDAR_LOGIN_SENHA =
"select "+
"count(numFunc) as total " +
"from "+
"tbfuncionario f "+
"where "+
"f.login_funcionario = ? and " +
"f.senha_funcionario = ?";
private static final String CONSULTA_FUNCIONARIOS =
"select * from tbfuncionario order by nomeFunc";
private static final String CONSULTA_FUNCIONARIO_ID =
"select * from tbfuncionario where numFunc = ?";
public boolean getAutenticacao(String nome, String senha) throws DaoException {
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
int numReg = 0;
boolean autenticado = false;
try {
statement = conn.prepareStatement(VALIDAR_LOGIN_SENHA);
statement.setString(1, nome);
statement.setString(2, senha);
result = statement.executeQuery();
if (result.next()) {
numReg = result.getInt("total");
}
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
if(numReg != 0){
return autenticado = true;
}else{
return autenticado;
}
}
public List<Funcionario> consultarFuncionarios() throws DaoException{
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
List<Funcionario> listaFunc = new ArrayList<Funcionario>();
try {
statement = conn.prepareStatement(CONSULTA_FUNCIONARIOS);
result = statement.executeQuery();
while (result.next()) {
Funcionario objFunc = new Funcionario();
objFunc.setNumFunc(result.getInt(1));
objFunc.setNomeFunc(result.getString(2));
objFunc.setTelFunc(result.getString(3));
objFunc.setProfissaoFunc(result.getString(4));
objFunc.setLogin(result.getString(5));
objFunc.setSenha(result.getString(6));
objFunc.setSalarioFunc(result.getDouble(7));
listaFunc.add(objFunc);
}
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return listaFunc;
}
public Funcionario consultarFuncionarioID(int idFunc) throws DaoException{
Funcionario objFunc = new Funcionario();
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(CONSULTA_FUNCIONARIO_ID);
statement.setInt(1, idFunc);
result = statement.executeQuery();
while (result.next()) {
//JOptionPane.showMessageDialog(null, String.valueOf(result.getInt(1)));
objFunc.setNumFunc(result.getInt(1));
objFunc.setNomeFunc(result.getString(2));
objFunc.setTelFunc(result.getString(3));
objFunc.setProfissaoFunc(result.getString(4));
objFunc.setLogin(result.getString(5));
objFunc.setSenha(result.getString(6));
objFunc.setSalarioFunc(result.getDouble(7));
}
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return objFunc;
}
public int inserirFuncionarios(Funcionario obj, int matri) throws DaoException{
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(INSERIR_FUNCIONARIO);
statement.setString(1, obj.getNomeFunc());
statement.setString(2, obj.getTelFunc());
statement.setString(3, obj.getProfissaoFunc());
statement.setString(4, obj.getLogin());
statement.setString(5, obj.getSenha());
statement.setDouble(6, obj.getSalarioFunc());
statement.executeUpdate();
statement = conn.prepareStatement("select max(numFunc) from tbfuncionario");
result = statement.executeQuery();
result.next();
matri = result.getInt(1);
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return matri;
}
public boolean atualizarFuncionario(Funcionario objFunc) throws DaoException{
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(ATUALIZAR_FUNCIONARIO);
statement.setString(1, objFunc.getNomeFunc());
statement.setString(2, objFunc.getTelFunc());
statement.setString(3, objFunc.getProfissaoFunc());
statement.setString(4, objFunc.getLogin());
statement.setString(5, objFunc.getSenha());
statement.setInt(7, objFunc.getNumFunc()); //6
statement.setDouble(6, objFunc.getSalarioFunc());
statement.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return true;
}
public boolean atualizarFuncionarioFunc(Funcionario objFunc) throws DaoException{
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(ATUALIZAR_FUNCIONARIO_FOLHA);
statement.setString(1, objFunc.getNomeFunc());
//statement.setString(2, objFunc.getTelFunc());
statement.setString(3, objFunc.getProfissaoFunc());
statement.setDouble(6, objFunc.getSalarioFunc());
//statement.setString(5, objFunc.getLogin());
//statement.setString(6, objFunc.getSenha());
statement.setInt(7, objFunc.getNumFunc());
statement.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return true;
}
public boolean excluirFuncionarios(int idFuncioanrio) throws DaoException{
Connection conn = DbUtil.getConnection();
PreparedStatement statement = null;
ResultSet result = null;
try {
statement = conn.prepareStatement(EXCLUIR_FUNCIONARIO);
statement.setInt(1, idFuncioanrio);
statement.executeUpdate();
} catch (SQLException e) {
throw new DaoException(e);
} finally {
DbUtil.close(conn, statement, result);
}
return true;
}
}