A JavaBean is easy to implement various operations for the database

zhaozj2021-02-12  198

A JavaBean is easy to implement various operations for the database 1. Call instance <% @ page contenttype = "text / html" import = "OPERATE_DB. *, Java.SQL. *"%> <% string prm1, prm2, prm3; resultset RST = NULL; PRM1 = ...; prm2 = ...; prm3 = ...; queryBean.setConnection Sun.jdbc.odbc.jdbcodbcdriver "," JDBC: ODBC: Data Source Name "," SA "," "); try {string [] param = {PRM1, PRM2, PRM3}; / * Settings SELECT statement * / querybean .SETQUERYSTATEMENT ("SELECT *WELD2 =? and Field3 =?"); queryBean.SetParam (param); RST = querybean.getResult ();} catch (Exception E) {system.out.println (e);} while (RST.Next ()) {%> <% = RST.GETSTRING (1)%> <%}%> 2.javabean querybean querybean.java: pacakage operate_db; / ** * Title: SELECT insert update and delete * Description: select insert update and delete * Copyright: Copyright (c) 2001 * @author Lci21 * @version 1.0 * / import java.sql *; public class QueryBean {public String query_statement; / * define the sql statement. * / public string param []; / * Query criteria, or new record * / public resultset ult = null; public Connection conn; public void setParam (String [] param) {this.param = param;} public void setQuerystatement (String query_statement) {this.query_statement = query_statement;} public void setConnection (String driverName, String jdbcURL, String username, String passwd) throws Exception {Connection conn1; Class.forName (driverName); conn1 = DriverManager.getConnection (jdbcURL, username, passwd); conn1.setAutoCommit (false); this.conn = conn1;} / * Get query Results * / public resultset getResult () {try {preparedState select_stm =

conn.prepareStatement (query_statement, java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE, java.sql.ResultSet.CONCUR_READ_ONLY); if (param = null!) for (int i = 0; i

Preliminary article Title: ** Easily establish and manage the database connection pool! ** Easily implement page navigation and data paging display using JavaBean! ** Easily realize the processing of Chinese garbled using the final class static method! ** Easily implement the server-side detection of data types with JavaBean! ** Easily implement detection and processing of server-side date formats using JavaBean! ...... ... ...... Related Resources: JavaBean Connect Database Class

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

New Post(0)