1717
1818package org .apache .hugegraph .loader .test .functional ;
1919
20+ import org .apache .hugegraph .loader .exception .LoadException ;
21+
2022import java .sql .Connection ;
2123import java .sql .DriverManager ;
2224import java .sql .SQLException ;
2325import java .sql .Statement ;
2426
25- import org .apache .hugegraph .loader .exception .LoadException ;
26-
2727public class DBUtil {
2828
2929 private final String driver ;
@@ -40,33 +40,28 @@ public DBUtil(String driver, String url, String user, String pass) {
4040 this .pass = pass ;
4141 }
4242
43- public void connect () {
43+ public void connect (boolean useSSL ) {
4444 try {
4545 Class .forName (this .driver );
46- String url = String .format ("%s?%s" , this .url , " useSSL=false" );
46+ String url = String .format ("%s?useSSL= %s" , this .url , useSSL );
4747 this .conn = DriverManager .getConnection (url , this .user , this .pass );
4848 } catch (ClassNotFoundException e ) {
49- throw new LoadException ("Invalid driver class '%s'" ,
50- e , this .driver );
49+ throw new LoadException ("Invalid driver class '%s'" , e , this .driver );
5150 } catch (SQLException e ) {
52- throw new LoadException ("Failed to connect database via '%s'" ,
53- e , this .url );
51+ throw new LoadException ("Failed to connect database via '%s'" , e , this .url );
5452 }
5553 }
5654
57- public void connect (String database ) {
55+ public void connect (String database , boolean useSSL ) {
5856 this .close ();
59- String url = String .format ("%s/%s?%s" , this .url , database ,
60- "useSSL=false" );
57+ String url = String .format ("%s/%s?useSSL=%s" , this .url , database , useSSL );
6158 try {
6259 Class .forName (this .driver );
6360 this .conn = DriverManager .getConnection (url , this .user , this .pass );
6461 } catch (ClassNotFoundException e ) {
65- throw new LoadException ("Invalid driver class '%s'" ,
66- e , this .driver );
62+ throw new LoadException ("Invalid driver class '%s'" , e , this .driver );
6763 } catch (SQLException e ) {
68- throw new LoadException ("Failed to connect database via '%s'" ,
69- e , this .url );
64+ throw new LoadException ("Failed to connect database via '%s'" , e , this .url );
7065 }
7166 }
7267
0 commit comments