-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBDateMySql.java
More file actions
44 lines (35 loc) · 1.35 KB
/
Copy pathBDateMySql.java
File metadata and controls
44 lines (35 loc) · 1.35 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
package System;
import java.sql.*;
public class BDateMySql {
private static Connection connection;
public static final String url = "jdbc:mysql://localhost:3306/election"+
"?verifyServerCertificate=false"+
"&useSSL=false"+
"&requireSSL=false"+
"&useLegacyDatetimeCode=false"+
"&"+
"&serverTimezone=UTC";
public static final String user = "root";
public static final String password = "root";
private static void getConnection(String url, String login, String password) throws SQLException {
if (connection != null)
return;
connection = DriverManager.getConnection(url, login, password);
}
private static void createConnect() throws SQLException {
getConnection(BDateMySql.url, BDateMySql.user, BDateMySql.password);
}
public static ResultSet query(String query) throws SQLException {
createConnect();
Statement statement = connection.createStatement();
return statement.executeQuery(query);
}
public static int update(String query) throws SQLException {
createConnect();
Statement statement = connection.createStatement();
return statement.executeUpdate(query);
}
public static void closeConnection() throws SQLException {
connection.close();
}
}