1 |
duarte |
107 |
import tools.MySQLConnection; |
2 |
|
|
|
3 |
|
|
import java.sql.SQLException; |
4 |
|
|
import java.sql.Statement; |
5 |
|
|
import java.sql.ResultSet; |
6 |
|
|
|
7 |
|
|
public class testMySQLConnection { |
8 |
|
|
|
9 |
|
|
/** |
10 |
|
|
* "Hello World" for a MySQLConnection to white |
11 |
|
|
* |
12 |
|
|
* @author duarte |
13 |
|
|
*/ |
14 |
|
|
|
15 |
|
|
static String user = "duarte" ; // change user name!! |
16 |
|
|
|
17 |
duarte |
202 |
public static void main(String[] args){ |
18 |
duarte |
107 |
|
19 |
duarte |
202 |
MySQLConnection conn = null; |
20 |
|
|
try { |
21 |
|
|
conn = new MySQLConnection("white",user,"nieve","newmsdgraph"); |
22 |
|
|
} catch (SQLException e1) { |
23 |
|
|
e1.printStackTrace(); |
24 |
|
|
System.err.println("Can't connect to the db. Exiting"); |
25 |
|
|
System.exit(1); |
26 |
|
|
} |
27 |
duarte |
107 |
|
28 |
|
|
try { |
29 |
|
|
String sql = "SELECT num,res FROM nodes limit 3;"; |
30 |
|
|
Statement stmt = conn.createStatement(); |
31 |
|
|
ResultSet rsst = stmt.executeQuery(sql); |
32 |
|
|
while (rsst.next()) { |
33 |
|
|
int num = rsst.getInt(1); // 1st column -- num |
34 |
|
|
String res = rsst.getString(2); // 2nd column -- res |
35 |
|
|
System.out.println("serial number: "+num+", residue type: "+res); |
36 |
|
|
} |
37 |
|
|
} catch (SQLException e) { |
38 |
|
|
e.printStackTrace(); |
39 |
|
|
System.err.println("SQLException: " + e.getMessage()); |
40 |
|
|
System.err.println("SQLState: " + e.getSQLState()); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
} |