Accessing MS Access Database with Java
January 23rd, 2008 | by programming |1. Create a DNS name for your Access Database(*.mdb file) which you want to connect.
Start -> Settings -> Control Panel -> Data sources
Select Access in User Data Source
Click Create
Select Microsoft Access Driver
Click OK
Give a DSN Name and Descripton
Select the database *.mdb file
Click OK twice.
2. Now you have to use the DNS name (*) in establishing the connection in your java code as follows:
// my DNS name is MyOwn_DSN. you should have JDBCODBC Driver in your class path
DBInterface()
{
try
{
Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);
_pConnection = DriverManager.getConnection(”jdbc:odbc:MyOwn_DSN”,”",”");
_pStatement = _pConnection.createStatement();
}
catch(Exception e)
{
_bSavedStatus = false;
_sMessage = e.getMessage();
}
}