DB.java
上传用户:manager48
上传日期:2022-07-31
资源大小:997k
文件大小:2k
- /********************************************************************
- * Date:2007-04-03 *
- * File:DB.java *
- * Author:jezz *
- *********************************************************************/
- package wm.bean;
- import java.sql.*;
- import javax.naming.*;
- import javax.sql.DataSource;
- //一个用于查找数据源的工具类。
- public class DB {
- private Connection con=null;
- private Statement stmt=null;
- ResultSet rs=null;
- public ResultSet executeQuery(String sql) throws Exception
- {
- //rs=null;
- try
- {
- Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
- con = DriverManager.getConnection("proxool.xml-test");
- stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- rs=stmt.executeQuery (sql);
- }
- catch(SQLException e){throw e;}
- //catch(NamingException e){throw e;}
- return rs;
- }
- //执行Insert,Update语句
- public void executeUpdate(String sql) throws Exception
- {
- //stmt = null;
- //rs=null;
- try
- {
- Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
- con = DriverManager.getConnection("proxool.xml-test");//读取配置文件
- stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- stmt.executeUpdate(sql);
-
- }
- catch(SQLException ex)
- {
- System.err.println("执行SQL语句出错: " + ex.getMessage());
- }
- }
- // 关闭stmt和关闭连接
- public void all_close()
- {
- try{
- if(con!=null)
- con.close();
- //if(stmt!=null)
- //stmt.close();
- if(rs!=null)
- rs.close();
- }
- catch(SQLException e){e.printStackTrace();}
- }
- }