Database connection on java and access
import java.sql.*;/**
* Title: Garments
* Description:
* Copyright: Copyright (c) 2008
* Company: Null
* @author Iqbal
* @version 1.0
*/
public class DBManager
{
Statement stmt;
Connection con;
DB MANAGER
public DBManager()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename="I:/BCISPP/ICS.mdb";
String database="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";//have to assign space before writing the mdb
database+=filename.trim()+";DriverID=22;READONLY=true}";
con=DriverManager.getConnection(database,"","");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch(ClassNotFoundException cnfe)
{
System.out.println("Driver not found:"+cnfe);
}
catch(SQLException sqle)
{
System.out.println("SQL error:"+sqle);
}
}
public ResultSet getRecord(String strSql)throws SQLException
{
return stmt.executeQuery(strSql);
}
public boolean doQuery(String strSql)throws SQLException
{
return stmt.executeUpdate(strSql)>0;
}
public void closeDB()throws SQLException
{
stmt.close();
con.close();
}


