如标题所述,我在哪里可以找到一些资源,或者是否有人可以了解我应该使用哪些代码将J2EE程序连接到Access数据库?
谢谢!
答案 0 :(得分:0)
如果您可以使用J2SE连接Access Databse,那么您也可以使用J2EE进行连接(因为此部分的代码完全相同。)
您可以从这些主题中了解代码。
How to connect to Access .mdb database from 64-bit Java?
Java not connecting to MS Access database using Eclipse
这是一个教程看看
http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java
或者,
http://www.herongyang.com/JDBC/JDBC-ODBC-MS-Access-Connection.html
和As @Marc Estadillo说不要忘记司机。
答案 1 :(得分:0)
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;
}
}
}