As stated in the title, where can I find some resource or if there is anyone can shed some light on what codes I should use to connect a J2EE Program to an Access Database?
Thanks!
As stated in the title, where can I find some resource or if there is anyone can shed some light on what codes I should use to connect a J2EE Program to an Access Database?
Thanks!
If you can connect Access Databse using J2SE then you will be able to connect using J2EE too( as the code are exactly same for this portion.)
You can get an idea of code from these threads.
How to connect to Access .mdb database from 64-bit Java?
Java not connecting to MS Access database using Eclipse
Here is a tutorial give a look
http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java
or,
http://www.herongyang.com/JDBC/JDBC-ODBC-MS-Access-Connection.html
and As @Marc Estadillo said don't forget the driver.
Connection connection = null;
Statement stmt = null;
ResultSet rs = null;
String mySql = "SELECT ..."; // Put your query here.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try
{
// Arguments 2 and 3 are name and password if required
connection = DriverManager.getConnection("jdbc:odbc:myDriver", "", "");
stmt = connection.createStatement();
rs = stmt.executeQuery(mySql);
while (rs.next()) {
// do stuff with ResultSet
}
}
catch (SQLException sqle)
{
...
}
catch (Exception e)
{
...
}
finally
{
if (null != rs)
{
try
{
rs.close();
}
catch (Exception e)
{
...
}
finally
{
rs = null;
}
}
if (null != stmt)
{
try
{
stmt.close();
}
catch (Exception e)
{
...
}
finally
{
rs = null;
}
}
if (null != connection)
{
try
{
connection.close();
}
catch (Exception e)
{
...
}
finally
{
rs = null;
}
}
}