Java: Database Operation Package

xiaoxiao2021-03-06  14

Package creator.common.db; import java.io.inputstream; import java.sql. *; import javax.sql. *; import javax.naming. *; / ** * *

Title: dbbean.java *

description: *

Copyright: Copyright (c) 2004 *

company: * @Author tanbo * @version 1.0 * / public class dbbean {public java.sql.Connection conn = null; // connection object public ResultSet rs = null; // resultset object public Statement stmt = null; // statement object public PreparedStatement prepstmt = null; // preparedstatement object private String drivers = null ; // connection parameter: drivers private String url = null; // connection parameter: url private String user = null; // connection parameter: user private String password = null; // connection parameter: password private String jndi_name = null; / / Connection pool parameter: JNDI Name / ** * init () * / public dbbean () {Try {// parameter init drivers = creator.config.configbundle.getstring ("drivers"); URL = Creator.config.configbundle. Gets tring ( "url"); user = creator.config.ConfigBundle.getString ( "user"); password = creator.config.ConfigBundle.getString ( "password"); jndi_name = creator.config.ConfigBundle.getString ( "jndi_name" ); // DB connection pool init // initialcontext env = new initialContext (); //javax.sql.datasource pool = (javax.sql.datasource) env.lookup (jndi_name); // conn = pool.getConnection () ; // db connection init class.forname (drivers); conn = drivermanager.getConnection (URL, User, Password); // DB Statement Init STMT =

CONN.CREATESTATEMENT ();} catch (Exception E) {system.out.println ("dbbean: init error!" e.tostring ());}} / ** * @function prepareState * @Param SQL STRING * @ throws SQLException * / public void prepareStatement (String sql) throws SQLException {prepstmt = conn.prepareStatement (sql);} / ** * @function prepareStatement * @param sql String * @param resultSetType int * @param resultSetConcurrency int * @throws SQLException * / public void prepareStatement (String sql, int resultSetType, int resultSetConcurrency) throws SQLException {prepstmt = conn.prepareStatement (sql, resultSetType, resultSetConcurrency);} / ** * @function executeQuery * @param sql String * @throws SQLException * @ return ResultSet * / public ResultSet executeQuery (String sql) throws SQLException {if (stmt = null!) {return stmt.executeQuery (sql);} else return null;} / ** * @function executeQuery * @throws SQLException * @return ResultSet * / Public ResultSet executeQuery () throws SQLException {if (prepstmt = null!) {Return prepstmt.executeQuery ();} else return null;} / ** * @function executeUpdate * @param sql String * @throws SQLException * / public void executeUpdate (String sql) throws SQLException {if (stmt = null!) stmt.executeUpdate (sql);}! / ** * @function executeUpdate * @throws SQLException * / public void executeUpdate () throws SQLException {if (prepstmt = null ) Prepstmt.executeUpdate ();} / ** * @function executeUpdate * @

throws SQLException * / public void executeBatch () throws SQLException {if (prepstmt = null!) prepstmt.executeBatch ();} / ** * @function addBatch * @param value String * @throws SQLException * / public void addBatch (String value ) throws SQLException {prepstmt.addBatch (value);} / ** * @function setString * @param index int * @param value String * @throws SQLException * / public void setString (int index, String value) throws SQLException {prepstmt. setString (index, value);} / ** * @function setInt * @param index int * @param value int * @throws SQLException * / public void setInt (int index, int value) throws SQLException {prepstmt.setInt (index, value);} / ** * @function setBoolean * @param index int * @param value boolean * @throws SQLException * / public void setBoolean (int index, boolean value) throws SQLException {prepstmt.setBoolean (index, value);} / ** * @function setdate * @Param index int * @Param Value Dat e * @throws SQLException * / public void setDate (int index, Date value) throws SQLException {prepstmt.setDate (index, value);} / ** * @function setLong * @param index int * @param value long * @throws SQLException * / public void setLong (int index, long value) throws SQLException {prepstmt.setLong (index, value);} / ** * @function setFloat * @param index int * @param value float * @throws SQLException * / public Void setfloat (int index, float value) throws sqlexception {prepstmt.setfloat (index, value);} / ** * @Function setBytes * @Param index int * @Param value byte [] * @

throws SQLException * / public void setBytes (int index, byte [] value) throws SQLException {prepstmt.setBytes (index, value);} / ** * @function setBinaryStream * @param index int * @param value InputStream * @param len int * @throws SQLException * / public void setBinaryStream (int index, InputStream value, int len) throws SQLException {prepstmt.setBinaryStream (index, value, len);} / ** * @function setTimestamp * @param index int * @param timestamp timestamp * @throws SQLException * / public void setTimestamp (int index, timestamp timestamp) throws SQLException {prepstmt.setTimestamp (index, timestamp);} / ** * @function setAutoCommit * @param value boolean * @throws SQLException * / public void setAutoCommit (boolean value) throws SQLException {if (this.conn = null!) this.conn.setAutoCommit (value);} / ** * @function commit * @throws SQLException * / public void commit () throws SQLException {this .conn.commit ();} / ** * @Function rollback * @throws SQLException * / public void rollback () throws SQLException {this.conn.rollback ();} / ** * @function close * @throws Exception * / public void close () {try {if (rs =! NULL) {r.close (); rs = null;}} catch (exception e) {system.out.println ("DBBean Close Rs Error!");} finally {try {if (stmt! = null) {stmt .close (); stmt = null;}} catch (exception e) {system.out.println ("DBBean Close Stmt Error!");} Finally {Try {IF (prepstmt! = null) {prepstmt.close () Prepstmt =

转载请注明原文地址:https://www.9cbs.com/read-49906.html

New Post(0)