-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConexao.java
More file actions
61 lines (49 loc) · 1.66 KB
/
Conexao.java
File metadata and controls
61 lines (49 loc) · 1.66 KB
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
package br.edu.ifb.conexao;
import br.edu.ifb.DAO.ContatoDAO;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Conexao {
private static final String URL = "jdbc:sqlite:bancoAgenda.db";
public static Connection getConnection() {
try {
return DriverManager.getConnection(URL);
} catch (SQLException ex) {
System.out.println("Banco não conectado!");
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public static void closeConnection(Connection con){
try {
con.close();
} catch (SQLException ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt){
closeConnection(con);
try {
stmt.close();
} catch (SQLException ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void closeConnection(Connection con, PreparedStatement stmt, ResultSet rs){
closeConnection(con, stmt);
try {
rs.close();
} catch (SQLException ex) {
Logger.getLogger(Conexao.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
ContatoDAO ver = new ContatoDAO();
ver.lerBanco();
}
}