-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (34 loc) · 1.28 KB
/
Main.java
File metadata and controls
38 lines (34 loc) · 1.28 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
import com.mysql.jdbc.Driver;
import java.sql.*;
class Main {
public static void main(String args[]) throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Main t = new Main();
t.run();
}
void run() {
testConn("jdbc:mysql://docker.for.mac.localhost:4000/");
testConn("jdbc:mysql://docker.for.mac.localhost:4000/test");
testConn("jdbc:mysql://docker.for.mac.localhost:4000/1234.test");
testConn("jdbc:mysql://docker.for.mac.localhost:4000/42.test");
testConn("jdbc:mysql://docker.for.mac.localhost:4000/42");
}
void testConn(String s) {
System.out.println("conn using: " + s);
try {
Connection conn = DriverManager.getConnection(s+"?user=root");
Statement stmt = conn.createStatement();
try {
ResultSet rs = stmt.executeQuery("SELECT DATABASE();");
if (rs.next()) {
System.out.println("using db:" + rs.getString(1));
}
} catch (Exception e) {
System.out.println("exec error:" + e);
}
} catch (Exception e) {
System.out.println("connect error:" + e);
}
System.out.println("--");
}
}