Java connect Access database code
Import java.sql .*;
(Public class dbaccess
Public static void main (String args []) throws Exception (
Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver");
String dburl = "jdbc: odbc: driver = (Microsoft Access Driver (*. mdb)); Mobile.mdb DBQ =" / / NO-DSN This is the way
(Public class dbaccess
Public static void main (String args []) throws Exception (
Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver");
String dburl = "jdbc: odbc: driver = (Microsoft Access Driver (*. mdb)); Mobile.mdb DBQ =" / / NO-DSN This is the way
/ / String dburl = "jdbc: odbc: odbcName" / / This is the ODBC connections
Connection conn = DriverManager.getConnection (dburl);
Statement stmt = conn.createStatement ();
ResultSet rs = stmt.executeQuery ( "select Top 20 * from MobileSection");
System.out.println ( "paragraph \ t region \ t \ t provinces \ t 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 ();
)
)
Connection conn = DriverManager.getConnection (dburl);
Statement stmt = conn.createStatement ();
ResultSet rs = stmt.executeQuery ( "select Top 20 * from MobileSection");
System.out.println ( "paragraph \ t region \ t \ t provinces \ t 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 ();
)
)
The result:
Run Java ———- ———-
Provinces of the region, type code
1300566 Maoming, Guangdong Unicom Guangdong 130 cards 0668
1300567 Maoming, Guangdong Unicom Guangdong 007 cards 0668
1300568 Maoming, Guangdong Unicom Guangdong 007 cards 0668
1300569 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300570 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300571 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300572 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300573 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300574 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300575 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300576 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300577 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300578 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300579 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
Provinces of the region, type code
1300566 Maoming, Guangdong Unicom Guangdong 130 cards 0668
1300567 Maoming, Guangdong Unicom Guangdong 007 cards 0668
1300568 Maoming, Guangdong Unicom Guangdong 007 cards 0668
1300569 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300570 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300571 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300572 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300573 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300574 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300575 Huizhou Guangdong Unicom Guangdong 130 cards 0752
1300576 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300577 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300578 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
1300579 Zhuhai in Guangdong Unicom Guangdong 130 cards 0756
Tags: java access, java code
Releated Java Articles
June 19, 2006 | Filed Under Java Developement Tools |






