/ * There are two ways to connect to the database with JDBC. DataBase can be freely moved, such as the database of personal sites, more advantage. Here I talk about the feelings you have developed in this way. I hope to help everyone. Operating environment: Win2k Advance Server (English version), JSDK 1.4.1 Microsoft Access Database (Office XP Series) * /
/ ** * @Author wolfhan * @version 12/18/2002 * @since jdk 1.4.0 * / import java.io. *; Import java.sql. *;
Public class mobileDatabase {public static void main (string [] args) {try {// load jdbc driver class.Forname ("Sun.jdbc.odbc.jdbcodbcdriver"); / * The URL of the database here must write correctly, this It is the key, where DBQ can absolute path, or a relative path, in order to reflect the / independence of the data storage path, you can try the database COPY to a different bit * / string dburl = "JDBC: ODBC: driver = {Microsoft Access Driver (* .mdb)}; DBQ = access // test.mdb "; Connection con = DriverManager.getConnection (dbUrl," "," "); Statement state = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE) ; // Execute SQL statement string SQL = "Select * from address"; resultset = state.executeQuery (SQL);
// Print the test if (rs! = Null) {while (rs.next ()) {system.out.println ("/ t" rs.getstring ("name"));}}}}} rs.close (); conn . close ();}} catch (exception e) {E.PrintStackTrace ();}}
} // End Class MobileDatabase
Attachment: Database Test.mdb Structure Design: Field Type Length (bytes) -------------------------- Name Text 8 SEX Bool (System Specified) AGE INT 20 ----------------------------- Since adding a few records to the inside The result can be measured.