JDBC-ODBC connection database

zhaozj2021-02-16  52

/ * JDBC-ODBC connection database * / package dbjavabean;

Import java.sql. *;

Public class officeb {

String sdbdriver = "sun.jdbc.odbc.jdbcodbcdriver"; string sconnstr = "jdbc: odbc: one"; connection conn = null; ResultSet RS = NULL;

Public openb () {try {class.forname (sdbdriver);} catch (java.lang.classnotnetfoundexception e) {system.err.print (E.GetMessage ());}}

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.Print (ex.getMessage ());} Return Rs;}}

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

New Post(0)