star123456789
发贴: 4
|
于 2006-10-20 17:51
/** * @(#)dbConnect.java * * * @author star * @version 1.00 2006/10/20 */ package dbConnect; import java.sql.*;
public class dbConnect {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String sDBSourse = ""; Connection conn = null; Statement stmt = null; ResultSet rs = null; public dbConnect() { try{ Class.forName(sDBDriver); } catch(ClassNotFoundException ce){ System.out.println(ce.getMessage()); } } public ResultSet executeQuery(String dbSourse, String sql){ try{ sDBSourse = dbSourse; conn = DriverManager.getConnection("jdbc:odbc:" + sDBSourse); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); } catch(SQLException e){ System.out.println (e.getMessage()); } return rs; } public int executeUpdate(String dbSourse, String sql){ int result = 0; try{ sDBSourse = dbSourse; conn = DriverManager.getConnection("jdbc:odbc:"+ sDBSourse); stmt = conn.createStatement(); result = stmt.executeUpdate(sql); } catch(SQLException e){ System.out.println (e.getMessage()); } return result; } public void close() { try{ if(rs != null) rs.close(); if(stmt != null) stmt.close(); if(conn != null) conn.close(); } catch(SQLException e){ System.out.println (e.getMessage()); } } }
|