Although simple, for beginners, without a piece of code can be successfully executed for reference, it is difficult to debug
First use access to build a database DB1. MDB, which has a table "table1" with Field "Name" and "age"
Just fill in a few records, save to the ODBC to build a system data source "Access2000" connected to this database
You can then use the following code to display all the records in the database.
Database.java
------------------
Import java.sql.*;
Class Database {
public static void Main (String args[]) {
try{
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
String url= "jdbc:odbc:Access2000";
Connection connection=drivermanager.getconnection (URL);
Statement Statement = Connection.createstatement ();
String sql= "SELECT * from table1";
ResultSet rs = statement.executequery (SQL);
String tt;
while (Rs.next ()) {
System.out.print ("Name:" + rs.getstring ("name"));
System.out.println ("Age:" + rs.getstring ("aged"));
}
Rs.close ();
Connection.close ();
}
catch (Exception ex) {
System.out.println (ex);
System.exit (0);
}
}
}
------------
OK, compile run:
E:/java>javac Database.java
E:/java>java Database