// JDBC RMI Database connection -- database connection object import java.sql.*; public class JRConnection { private Connection con; // Database connection object private Statement stmt; // SQL statement object private ResultSet rs; // SQL query results public JRConnection() { rs = null; stmt = null; con = null; } public void openDatabase() throws SQLException, ClassNotFoundException { // Load the JDBC-ODBC bridge driver Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); // Connect to the database con = DriverManager.getConnection("jdbc:odbc:Northwind", "admin", ""); } /** Issue a SQL query with a WHERE clause */ public void performSearch(String searchString) throws SQLException { String query; // SQL select string // build the query command query = "SELECT EmployeeID, LastName, FirstName, Title " + "FROM Employees "; if (!searchString.equals("")) { query += "WHERE " + searchString; } stmt = con.createStatement(); rs = stmt.executeQuery(query); } public String getNextRow() throws SQLException { if (rs.next()) { return rs.getInt("EmployeeId") + ", " + rs.getString("FirstName") + " " + rs.getString("LastName") + ", " + rs.getString("Title"); } rs.close(); rs = null; stmt.close(); stmt = null; return null; } public void closeDatabase() throws SQLException { if (rs != null) rs.close(); if (stmt != null) stmt.close(); if (con != null) con.close(); rs = null; stmt = null; con = null; } }