import java.sql.*;
/**
* This class is used to retreive images from
* an MS Access database.
*/
public class DataObject {
private Connection con;
public DataObject(String databaseName) {
// Connect to the database
connect(databaseName);
}
/**
* This method attempts to load the default driver
* and connect to the specified database.
*
* @param dbName The database name
*/
private void connect(String dbName) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(
"jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ="+dbName+".mdb");
} catch (ClassNotFoundException ce) {
System.out.println(ce.getMessage());
} catch (SQLException se) {
System.out.println(se.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
/**
* This method attempt to disconnect from the currently
* connected database.
*/
public void disconnect() {
try {
con.close();
} catch (SQLException se) {
System.out.println(se.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
}
}
}