-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionFactory.java
54 lines (29 loc) · 1007 Bytes
/
ConnectionFactory.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
package com.mydb.test;
import com.mysql.jdbc.Driver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectionFactory {
public static final String URL = "jdbc:mysql://localhost:3306/user_pref";
public static final String USER = "root";
public static final String PASS = "asdf";
/**
* Get a connection to database
* @return Connection object
*/
public static Connection getConnection()
{
try {
DriverManager.registerDriver(new Driver());
return DriverManager.getConnection(URL, USER, PASS);
} catch (SQLException ex) {
throw new RuntimeException("Error connecting to the database", ex);
}
}
/**
public static void main(String[] args) {
Connection connection = ConnectionFactory.getConnection();
System.out.println(connection.toString());
}
*/
}