java连接Access数据库代码
闲来无事,整理了一下Java代码。算做个复习笔记了。importjava.sql.
;
publicclassdbAccess{
publicstaticvoidmain(Stringargs)throwsException{
Class.forName(sun.JDBC.odbc.JdbcOdbcDriver);
Stringdburl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>dbc:driver={MicrosoftAccessDriver(
.mdb)};DBQ=Mobile.mdb;//此为NO-DSN方法
//Stringdburl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>dbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>dbcName;//此为ODBC连接方法
Connectionconn=DriverManager.getConnection(dburl);
Statementstmt=conn.createStatement();
ResultSetrs=stmt.executeQuery(selectTop20
fromMobileSection);
System.out.println(号段\t地区\t类型\t份\t区号);
while(rs.next()){
System.out.println(rs.getString(1)+\t+rs.getString(2)+\t+rs.getString(3)+\t+rs.getString(4)+\t+rs.getString(5));
}
rs.close();
stmt.close();
conn.close();
}
}
(When I have nothing to do, I sorted out the Java code. It's a review note.
importjava.sql.
;
publicclassdbAccess{
publicstaticvoidmain(Stringargs)throwsException{
Class.forName(sun.JDBC.odbc.JdbcOdbcDriver);
Stringdburl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>dbc:driver={MicrosoftAccessDriver(
.mdb)};DBQ=Mobile.mdb;//This is the NO-DSN method
//Stringdburl=jdbc<imgsrc="static/image/smiley/default/shocked.gif"smilieid="6"border="0"alt=""/>dbc<imgsrc="static/image/smiley/default/ shocked.gif"smilieid="6"border="0"alt=""/>dbcName;//This is the ODBC connection method
Connectionconn=DriverManager.getConnection(dburl);
Statementstmt=conn.createStatement();
ResultSetrs=stmt.executeQuery(selectTop20
fromMobileSection);
System.out.println(number segment\t area\t type\t copy\t area code);
while(rs.next()){
System.out.println(rs.getString(1) \t rs.getString(2) \t rs.getString(3) \t rs.getString(4) \t rs.getString( 5));
}
rs.close();
stmt.close();
conn.close();
}
})
页:
[1]