ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/owl/trunk/testMySQLConnection.java
Revision: 202
Committed: Thu Jun 21 17:18:11 2007 UTC (17 years, 4 months ago) by duarte
File size: 1129 byte(s)
Log Message:
MySQLConnection now throwing SQLException on connect
Many files changed following this: all calling classes now re-throwing or catching the SQLException
Line File contents
1 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 public static void main(String[] args){
18
19 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
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 }