-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQLConnection.java
More file actions
34 lines (28 loc) · 909 Bytes
/
Copy pathMySQLConnection.java
File metadata and controls
34 lines (28 loc) · 909 Bytes
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
package searchPackage;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MySQLConnection {
static Connection connectSQL() {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
}
catch (Exception ex){
ex.printStackTrace();
System.out.print("Exception Driver: " + ex);
}
Connection connectionSQL = null;
try {
connectionSQL = DriverManager.getConnection("jdbc:mysql://localhost:3308/slutprojekt?serverTimezone=UTC",
DatabaseLoginMySQLJava.getuserName(), DatabaseLoginMySQLJava.getuserPass());
}
catch (SQLException ex) {
ex.printStackTrace();
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
System.out.println("**********Database connected**********");
return connectionSQL;
}
}