-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmpresaDAO.java
81 lines (66 loc) · 2.44 KB
/
EmpresaDAO.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package markup;
import java.sql.*;
/**
*
* @author robssoares
*/
public class EmpresaDAO {
public Empresa empresa;
public BD bd;
private PreparedStatement statement;
private ResultSet resultSet;
private String men, sql;
public static final byte INCLUSAO = 1;
public static final byte ALTERACAO = 2;
public static final byte EXCLUSAO = 3;
public EmpresaDAO() {
bd = new BD();
empresa = new Empresa();
}
public boolean localizar(){
sql = "select idEmpresa, nomeEmpresa from markup_empresas where idEmpresa = ?";
try {
statement = bd.connection.prepareStatement(sql);
statement.setInt(1, empresa.getIdEmpresa());
resultSet = statement.executeQuery();
resultSet.first();
empresa.setIdEmpresa(resultSet.getInt(1));
empresa.setNomeEmpresa(resultSet.getString(2));
return true;
} catch (SQLException erro) {
return false;
}
}
public String atualizar(int operacao){
men = "Operacao realizada dom sucesso !";
try {
if (operacao ==INCLUSAO){
sql = "insert into markup_empresas(idEmpresa, nomeEmpresa) values(?,?)";
statement = bd.connection.prepareStatement(sql);
statement.setInt(1, empresa.getIdEmpresa());
statement.setString(2, empresa.getNomeEmpresa());
}
else if (operacao ==ALTERACAO){
sql = "update markup_empresas set nomeEmpresa = ? " +
"where idEmpresa = ? ";
statement = bd.connection.prepareStatement(sql);
statement.setInt(2, empresa.getIdEmpresa());
statement.setString(1, empresa.getNomeEmpresa());
}
else if (operacao ==EXCLUSAO) {
sql = "delete from markup_empresas where idEmpresa=?";
statement = bd.connection.prepareStatement(sql);
statement.setInt(1, empresa.getIdEmpresa());
}
if (statement.executeUpdate() ==0)
men = "falha na operacao ";
}catch (SQLException erro) {
men = "Falha na operacao !" + erro.toString();
}
return men;
}
}