*********************************************************** Inbergon 10:24 2003-12-16 ************************************************************ ******** JSP Operating Environment: Windows2000 Tomcat-4.1.24 J2SDK-1_4_1_01-Windows-i586 JDBCFORSQL2000 SQL2000 ****************** ***************************************** Tomcat 4.1 / WebApps / Examples / Web-INF / CLASSEES / OPENDB **** ****************************************************** Establishment File: OPENDB The contents of the .java file is as follows: Note that the file is appropriately modified according to the database connection. ********************************* **************** PACKAGE OPENDB;
Import Java.io.printStream; import java.sql. *;
Public class officeb {
STRING SDBDRIVER; STRING SCONNSTR; STRING SDBPASWD; Connection Conn; ResultSet RS;
public opendb () {sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; sConnStr = "jdbc: microsoft: sqlserver: //187.186.0.54: 1433; databaseName = e_bizbid_netstars_com_cn"; sDBuser = "sa"; sDBpasswd = " gyb "; conn = null; rs = null; try {Class.forName (sDBDriver);} catch (ClassNotFoundException classnotfoundexception) {System.err.println (" opendb (): " classnotfoundexception.getMessage ());}}
public ResultSet executeQuery (String s) {rs = null; try {conn = DriverManager.getConnection (sConnStr, sDBuser, sDBpasswd); Statement statement = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = statement.executeQuery (s );} catch (SQLException sqlexception) {System.err.println ( "aq.executeQuery:" sqlexception.getMessage ());} return rs;} public void executeUpdate (String sql) {try {conn = DriverManager.getConnection ( sConnStr, sDBuser, sDBpasswd); Statement stmt = conn.createStatement (); stmt.executeUpdate (sql);} catch (SQLException ex) {System.err.println ( "aq.executeUpdate:" ex.getMessage ()); System.err.Println ("AQ.ExecuteUpadateSTRSQL:" SQL);}} / ** * Get another field according to a field in the table * Xu Cui July 15, 2003 * / public string executeQuery_get_fieldvalue (String Field1, String Fiel D1_VALUE, STRING FIELD2, STRING TABLE1) {String S, FIELD2_VALUE; S = "SELECT" Field2 "from" Table1 "Where" Field1 "= '" Field1_Value "'"; RS = null; Field2_Value = null; try {conn = DriverManager.getConnection (sConnStr, sDBuser, sDBpasswd); Statement statement = conn.createStatement (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = statement.executeQuery (s); while (rs.next () ) {Field2_Value = rs.getstring (field2);
}}}}}}} {System.err.println ("AQ.ExecuteQuery:" SQLEXCEPTION.GETMESSAGE ());} Return Field2_Value;}} ************************ *********************************************************** **************** Copy OpenDb.java into the openDb.class file to Tomcat 4.1 / WebApps / Examples with the Java Compiler (J2SDK / BIN / JAVAC.EXE) / Web-INF / CLASSES / OPENDB directory (new openDB directory) ******************************************* ************************************************ Instructions : Add: