66
77public class MySQL extends SQL {
88
9- /**
10- * Create MySQL connection.
11- * Do not worry about creating the database, AdvancedSQL takes care of it for you.
12- * @param host MySQL server host.
13- * @param port MySQL server port.
14- * @param username MySQL server username.
15- * @param password MySQL server password.
16- * @param database MySQL server database. If not exists AdvancedSQL creates it for you.
17- * @throws SQLException Exception when something goes wrong.
18- */
19- public MySQL (String host , int port , String username , String password , String database ) throws SQLException {
9+ public MySQL (String host , int port , String username , String password , String database , String attributes ) throws SQLException {
2010 try {
2111 Class .forName ("com.mysql.cj.jdbc.Driver" );
2212
23- this .connect (host , port , username , password , database );
13+ this .connect (host , port , username , password , database , attributes );
2414 } catch (SQLException e ) {
2515 if (e .getErrorCode () == 1049 ) {
2616 createDatabase (host , port , username , password , database );
2717
28- connect (host , port , username , password , database );
18+ connect (host , port , username , password , database , attributes );
2919
3020 return ;
3121 }
@@ -38,14 +28,28 @@ public MySQL(String host, int port, String username, String password, String dat
3828 }
3929 }
4030
41- private void connect (String host , int port , String username , String password , String database ) throws SQLException {
42- connection = DriverManager .getConnection ("jdbc:mysql://" + host + ":" + port + "/" + database + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" , username , password );
31+ /**
32+ * Create MySQL connection.
33+ * Do not worry about creating the database, AdvancedSQL takes care of it for you.
34+ * @param host MySQL server host.
35+ * @param port MySQL server port.
36+ * @param username MySQL server username.
37+ * @param password MySQL server password.
38+ * @param database MySQL server database. If not exists AdvancedSQL creates it for you.
39+ * @throws SQLException Exception when something goes wrong.
40+ */
41+ public MySQL (String host , int port , String username , String password , String database ) throws SQLException {
42+ this (host , port , username , password , database , "useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC" );
43+ }
44+
45+ private void connect (String host , int port , String username , String password , String database , String attributes ) throws SQLException {
46+ connection = DriverManager .getConnection ("jdbc:mysql://" + host + ":" + port + "/" + database + (attributes .isEmpty () ? "" : "?" + attributes ), username , password );
4347
4448 this .connected = true ;
4549 }
4650
4751 private void createDatabase (String host , int port , String username , String password , String database ) throws SQLException {
48- connection = DriverManager .getConnection ("jdbc:mysql://" + host + ":" + port + "?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC " , username , password );
52+ connection = DriverManager .getConnection ("jdbc:mysql://" + host + ":" + port + "?" , username , password );
4953
5054 Statement statement = connection .createStatement ();
5155
0 commit comments