Database connection is the most important part for dynamic websites. The connection technology in Java is JDBC (Java Database Connectivity ). Many database systems have JDBC drivers. The Java program connects to the database through the JDBC driver and performs operations such as querying and extracting data. Sun also developed JDBC-ODBC bridge, with this technology Java program can access the database with ODBC driver, currently most database systems with ODBC driver, therefore, Java programs can Access databases such as Oracle, Sybase, ms SQL Server, and MS Access. The following describes how to use Access to implement a dynamic FAQ (FAQs and answers) website. First, create an Access database faq. mdb, where the table faqs has the field id (automatic incremental type, and set as the primary keyword), subject (text type, length 200), and answers (Remarks type ). This table can store some common programming knowledge questions and answers. Then, add the System DSN to the ODBC Datasource module of the Control Panel, name the faq, and point to faq. mdb. Create a JavaBean named faq. java and save it under the jswdk-1.0.1webpagesWEB-INFjspeans est directory. Faq. java:
Package test;
Import java. SQL .*;
Public class faq {
String sDBDriver = "sun. jdbc. odbc. JdbcOdbcDriver ";
String sConnStr = "jdbc: odbc: faq ";
Connection conn = null;
ResultSet rs = null;
Public faq (){
Try {
Class. forName (sDBDriver );
}
Catch (java. lang. ClassNotFoundException e ){
System. err. println ("faq ():" + e. getMessage ());
}
}
Public ResultSet executeQuery (String SQL ){
Rs = null;
Try {
Conn = DriverManager. getConnection (sConnStr );
Statement stmt = conn. createStatement ();
Rs = stmt.exe cuteQuery (SQL );
}
Catch (SQLException ex ){
System. err. println ("aq.exe cuteQuery:" + ex. getMessage ());
}
Return rs;
}