-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTest.java
More file actions
83 lines (49 loc) · 1.78 KB
/
Copy pathMyTest.java
File metadata and controls
83 lines (49 loc) · 1.78 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package jdbcTesting;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import jdbcTesting.Table;
public class MyTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
//Class.forName("org.postgresql.Driver");
DriverManager.registerDriver(new org.postgresql.Driver());
}catch(Exception e){
}
try {
String DB_URL = "jdbc:postgresql://localhost:5432/imdb";
String USER = "imdbuser";
String PASS = "eicklerSS18";
Connection conn = DriverManager.getConnection("jdbc:postgresql://127.0.0.1:5433/imdb",
"imdbuser","eicklerSS18");
Statement stm = conn.createStatement();
DatabaseMetaData dbMeta = conn.getMetaData();
ResultSet myRs = dbMeta.getSchemas();
// while(myRs.next()) {
// System.out.println(myRs.getString(1));
// }
ArrayList<Table> userTables= new ArrayList<Table>();
String[] table_types = {"TABLE"};
ResultSet tables = dbMeta.getTables("", "", "", table_types);
while (tables.next()) {
Table nt = new Table();
nt.setTableName(tables.getString(3));
userTables.add(nt);
}
ResultSet col;
for(Table t : userTables) {
col = dbMeta.getColumns(null, null,t.getTableName(), null);
System.out.println(t.getTableName()+ "\n" + "-------------------");
while (col.next()) {
System.out.print("column " +col.getString("COLUMN_NAME"));
System.out.println(" of type " + col.getString("TYPE_NAME"));
t.addColumn(col.getString("COLUMN_NAME"), col.getString("TYPE_NAME"));
}
System.out.println("++++++++++++\n");
}
}catch(Exception e) {
e.printStackTrace();
}
}
}