Connection+Class

package newGrade11;

import java.sql.*;import javax.swing.JOptionPane;

public class DBConnectUsers { Connection conn; public DBConnectUsers { //load the driver try { Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println ("Driver successfully loaded"); } catch (ClassNotFoundException c) {

System.out.println ("Unable to load database driver"); }

//connect to the database try {

String filename = "Grade11.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; database += filename.trim + ";DriverID=22;READONLY=true}"; conn = DriverManager.getConnection (database, "", ""); System.out.println ("Connection to database successfully established"); }

catch (Exception e) {

JOptionPane.showMessageDialog(null,"Unable to connect to the database"); } } //end connect

public void updateTbl(String sqlStmt) throws SQLException { Statement stmt = conn.createStatement; stmt.executeUpdate(sqlStmt); stmt.close; }//updateTbl

ResultSet queryTbl(String sqlStmt) throws SQLException {

Statement stmt = conn.createStatement; ResultSet rs = stmt.executeQuery(sqlStmt); return rs; }//queryTbl

}