-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
82 lines (66 loc) · 1.78 KB
/
Copy pathExample.java
File metadata and controls
82 lines (66 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
import java.util.*;
import java.sql.*;
public class Example {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new Example();
}
public Example() {
try
{
//*******************************************************
// CONNECT TO DATABASE
//
//
// check for jdbc driver
Class.forName("org.postgresql.Driver");
String url = "jdbc:postgresql://ec2-54-204-24-202.compute-1.amazonaws.com:5432/d95r26089mgb07";
Properties props = new Properties();
props.setProperty("user", "enheidiptehcsa");
props.setProperty("password", "EM9N7RPQOHUE00fsf12hPRlOfN");
props.setProperty("ssl", "true");
props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
//
// connect to the database
Connection conn = DriverManager.getConnection(url,props);
//
//*******************************************************
//*******************************************************
// build the query and get result from result set
//
//
String query = "SELECT * FROM \"NODEDESCRIPTION\" WHERE \"TYPE\" = 0";
//
//
// create statement and execute query
//
//
Statement stmt2 = conn.createStatement();
//
ResultSet rs2 = stmt2.executeQuery(query); // return a result set
//
//
//step through all records in the result set and print contents
//
//
while(rs2.next()) {
//
String sid = rs2.getString("SID");
//
String desc = rs2.getString("Description");
//
System.out.println("SID = " + sid + " Description = " + desc);
}
//******************************************************
// close the database connection
conn.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}