This is written about JSP call JavaBean Implementation database connection and operation!
First of all, JavaBean's original program.
——————————————————————
Package mywebconn;
Import java.sql.*;
public class Jdbcrs {
//
Static final String sdbdriver= "Sun.jdbc.odbc.JdbcOdbcDriver";
Static final String sconnstr= "Jdbc:odbc:driver={microsoft Access Driver (*.mdb)};D Bq=d:/myweb01/webmodule1/test.mdb" ;
Connection Conn=null;
ResultSet Rs=null;
Public Jdbcrs () {
try {
Class.forName (Sdbdriver);
}
catch (Java.lang.ClassNotFoundException e) {
System.err.println (E.getmessage ());
}
}
The public
Public ResultSet executequery (String sql) {
Rs=null;
try {
Conn=drivermanager.getconnection (SCONNSTR);
Statement stmt=conn.createstatement ();
Rs=stmt.executequery (SQL);
}
catch (SQLException ex) {
System.err.println ("Aq.executequery" +ex.getmessage ());
}
Return RS;
}
public void executeupdate (String sql) {
try {
conn = Drivermanager.getconnection (SCONNSTR);
Statement stmt = Conn.createstatement ();
Stmt.executeupdate (SQL);
Conn.close ();
}
catch (SQLException ex) {
System.err.println ("Aq.executeupdate" +ex.getmessage ());
}
}
public void Close () {
try {
if (!conn.isclosed ()) {
Conn.close ();
}
catch (SQLException ex) {
System.err.println ("Conn.close" +ex.getmessage ());
}
}
}
——————————————————————