-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJDBC.java
More file actions
46 lines (41 loc) · 1.53 KB
/
JDBC.java
File metadata and controls
46 lines (41 loc) · 1.53 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
package models;
import java.sql.Connection;
import java.sql.DriverManager;
/**This class was retrieved from the C195 Software II Class Code Repository.
* @author Unknown
* @version Unknown
* @since 2021-12-13
*/
public abstract class JDBC {
private static final String protocol = "jdbc";
private static final String vendor = ":mysql:";
private static final String location = "//localhost/";
private static final String databaseName = "client_schedule";
private static final String jdbcUrl = protocol + vendor + location + databaseName + "?connectionTimeZone = SERVER"; // LOCAL
private static final String driver = "com.mysql.cj.jdbc.Driver"; // Driver reference
private static final String userName = "sqlUser"; // Username
private static String password = "Passw0rd!"; // Password
public static Connection connection; // Connection Interface
public static void openConnection()
{
try {
Class.forName(driver); // Locate Driver
connection = DriverManager.getConnection(jdbcUrl, userName, password); // Reference Connection object
System.out.println("Connection successful!");
}
catch(Exception e)
{
System.out.println("Error:" + e.getMessage());
}
}
public static void closeConnection() {
try {
connection.close();
System.out.println("Connection closed!");
}
catch(Exception e)
{
System.out.println("Error:" + e.getMessage());
}
}
}