simple as it is, for beginners, if there is no Code that can be successfully executed, really difficult to debug
use access to create a database db1.mdb. There is a table named "Table1" with the fields "name" and "Age".
just enter a few records, save it and create a system data source "Access2000" in ODBC to connect to this database
then you can use the following code to display all 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.exe cutequery (SQL );
String tt;
While (Rs. Next ()){
System. Out. Print ("name:" + Rs. getstring ("name "));
System. Out. println ("Age:" + Rs. getstring ("Age "));
}
Rs. Close ();
Connection. Close ();
}
Catch (exception ex ){
System. Out. println (Ex );
System. Exit (0 );
}
}
}
------------
OK, compile and run:
E:/Java> javac database. Java
E:/Java> Java Database