public class connectAccess{
public static void main(String[] args) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//access 路徑
String str1="jdbc:odbc:DRIVER=Microsoft Access Driver(*.mdb);DBQ=C:/acc.mdb";
Connection conn=DriverManager.getConnection(str1,"","");
Statement stmt = conn.createStatement();
ResultSet rs;
try
{
//select
rs = stmt.executeQuery("select * from data" );
while(rs.next())
{
String no=rs.getString("NO").toString();
}
//insert
stmt.executeUpdate("insert into data");
//update
stmt.executeUpdate("update data set NO=''");
} catch (Exception e) {
e.printStackTrace();
}finally{
stmt.close();
conn.close();
}
}
}
沒有留言:
張貼留言