-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBD.java
44 lines (38 loc) · 1.18 KB
/
BD.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
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package markup;
import java.sql.*;
/**
*
* @author roberta.soares
*/
public class BD {
public Connection connection = null ;
private final String DRIVER = "com.mysql.jdbc.Driver";
private final String DBNAME = "diallink";
private final String URL = "jdbc:mysql://192.168.1.12/" + DBNAME;
private final String LOGIN = "diallink";
private final String SENHA = "4321";
public boolean getConnection(){
try {
Class.forName(DRIVER);
connection = DriverManager.getConnection(URL, LOGIN, SENHA);
System.out.println("Conectou");
return true;
} catch (ClassNotFoundException erro) {
System.out.println("Driver não encontrado !" + erro.toString());
return false;
} catch (SQLException erro) {
System.out.println("Falha ao Conectar !" + erro.toString());
return false;
}
}
public void close() {
try {
connection.close();
System.out.println("Desconectou");
} catch (SQLException erro) {}
}
}