Connection conn = null;
Statement stmt1 = null;
System.out.println("Start write access...");
try {
String strurl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=abc.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //驱动程序
conn = DriverManager.getConnection(strurl); //建立连接对象
stmt1 = conn.createStatement();
System.out.println("append records:");
String sql = "insert into Table_A (Id,Description) values (504,?)";
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,"vvv");
ps.executeUpdate();
System.out.println("success.");
}
catch(ClassNotFoundException cnfe)
{
System.out.println("error:" + cnfe.getMessage());
}
catch(SQLException sqlExp)
{
System.out.println("error:" + sqlExp.getMessage());
}
catch(Exception e)
{
System.out.println("error:" + e.getMessage());
}
finally
{
if(stmt1 != null)
{
try
{
stmt1.close();
}
catch(Exception e)
{
System.out.println("error:" + e.getMessage());
}
}
if(conn != null)
{
try
{
conn.close();
}
catch(Exception e)
{
System.out.println("error:" + e.getMessage());
}
}
}