Chapter 15
616
enter "travel" for the Data Source Name and a short description of the database. Now select the
database from the download code (as shown) and press OK through to the finish. This will allow us to
refer to the database using the URI jdbc:odbc:travel.
Here is sqlBean.java that uses it:
package com.wrox.pjxml;
import java.sql.Connection;
import java.sql.DriverManager;
public class sqlBean {
private String myDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
private String myURL = "jdbc:odbc:travel";
protected Connection myConn;
public sqlBean() {}
public void makeConnection() throws Exception {
Class.forName( myDriver);
myConn = DriverManager.getConnection(myURL);
}
public void takeDown() throws Exception {
myConn.close();
}
}
queryBean supports the single query method, getDeals(). getNextTrip() is used to iterate
through the JDBC Resultset that is returned from this query.
package com.wrox.pjxml;
public class queryBean extends sqlBean {
String myTripQuery = "select * from hotdeals where tripno > ";
ResultSet myResultSet = null;
public queryBean() {super();}
public boolean getDeals(String tripNo) throws Exception {
String myQuery = myTripQuery + tripNo;
Statement stmt = myConn.createStatement();
myResultSet = stmt.executeQuery(myQuery);
return (myResultSet != null);
}
public boolean getNextTrip() throws Exception {
return myResultSet.next();
}
public String getColumn( String inCol) throws Exception {
return myResultSet.getString(inCol);
}
}