17
17
18
18
package org .apache .hugegraph .loader .test .functional ;
19
19
20
+ import org .apache .hugegraph .loader .exception .LoadException ;
21
+
20
22
import java .sql .Connection ;
21
23
import java .sql .DriverManager ;
22
24
import java .sql .SQLException ;
23
25
import java .sql .Statement ;
24
26
25
- import org .apache .hugegraph .loader .exception .LoadException ;
26
-
27
27
public class DBUtil {
28
28
29
29
private final String driver ;
@@ -40,33 +40,28 @@ public DBUtil(String driver, String url, String user, String pass) {
40
40
this .pass = pass ;
41
41
}
42
42
43
- public void connect () {
43
+ public void connect (boolean useSSL ) {
44
44
try {
45
45
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 );
47
47
this .conn = DriverManager .getConnection (url , this .user , this .pass );
48
48
} 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 );
51
50
} 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 );
54
52
}
55
53
}
56
54
57
- public void connect (String database ) {
55
+ public void connect (String database , boolean useSSL ) {
58
56
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 );
61
58
try {
62
59
Class .forName (this .driver );
63
60
this .conn = DriverManager .getConnection (url , this .user , this .pass );
64
61
} 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 );
67
63
} 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 );
70
65
}
71
66
}
72
67
0 commit comments