-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContaDao.java
33 lines (28 loc) · 883 Bytes
/
ContaDao.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
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ContaDao {
private Connection cnn;
public ContaDao() {
try {
//Class.forName("org.postgresql.Driver");
this.cnn = DriverManager.getConnection("jdbc:postgresql://localhost/dojo?user=postgres");
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void adiciona(Conta conta) {
try {
String sql = "insert into conta(agencia, conta, titular, saldo) values (?,?,?,?)";
PreparedStatement ps = cnn.prepareStatement(sql);
ps.setInt(1, conta.getAgencia());
ps.setInt(2, conta.getConta());
ps.setString(3, conta.getTitular());
ps.setDouble(4, conta.saldo);
ps.execute();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}