Database bottom connection

xiaoxiao2021-03-06  42

Package com.wen;

Import java.sql. *;

/ ** * Title: Database bottom connection * Description: * Copyright: Copyright (c) 2004 * company: * @Author Explorer * @version 1.0 * / public class linkdb {string striver = "sun.jdbc.odbc.jdbcodbcdriver"; // Load the driver string string string strConn = "jdbc: ODBC: dbserver"; private connection conn = null; private statement stmt = null; // Execute SQL statement ResultSet RS = NULL;

Public linkdb () {Try {class.forname (strdriver) .newinstance (); // ** newinstance () What does it mean? ** //} Catch (Exception E) {System.err.Println ("You cannot connect to the database!" E.getMessage ());}}

// Execute the SELECT statement public resultSet ExecuteQuery (String SQL) {Try {conn = driverManager.getConnection (StrConn, "SA", "SA"); // Establish connection between the connection between the data source (ResultSet). TYPE_SCROLL_SENSITIVE, RESULTSET.CONCUR_READ_ONLY); rs = stmt.executeQuery (SQL); // Reverse Result Set} catch (SQLEXCEPTION EX) {system.err.println ("Execute SQL statement error:" ex.getMessage ()); } Return RS;

// perform Insert, Update statement public void executeUpdate (String sql) {try {conn = DriverManager.getConnection (strConn, "sa", "sa"); stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); / / Page must add parameters stmt.executeQuery (SQL); stmt.close (); conn.close ();} catch (sqlexception ex) {system.rr.println ("Execute SQL statement error:" ex. maxMessage () }}

Public void closest () {Try {stmt.close ();} catch (sqlexception e) {E.PrintStackTrace ();}}

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

New Post(0)