⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 condb.java

📁 呼叫中心自助语声音
💻 JAVA
字号:
package com.bean;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.naming.*;


public class ConDB {
	 private Connection con;
     private PreparedStatement stmt;
     private ResultSet rs;
     public String path;
     public Connection getConnection() throws Exception
     {
         if(con == null)
         {
        	 Context env = new InitialContext(); 
        	 DataSource pool = (DataSource) env.lookup("java:comp/env/jdbc/oracle"); 
     	     if (pool == null) throw new Exception("jdbc/oracle is an unknown DataSource");
     	     con = pool.getConnection();
     	     con.setAutoCommit(false); 
     	     
         }
         return con;
     }
     
     public PreparedStatement getStatement(String sql) throws Exception
     {
         con = getConnection();
         stmt = con.prepareStatement(sql);
         return stmt;    
     }
     
     public ResultSet executeQuery(String sql,ArrayList paras) throws Exception
     {
         stmt = getStatement(sql);
         if (paras != null) 
         {
        	 Object o[] = paras.toArray();
        	 for (int i = 0; i < o.length; i++) 
        	 {
        		 if (o[i] instanceof String)
        		 {
        			 stmt.setString(i + 1, (String) o[i]);
        		 }
        	 }
         }
         return stmt.executeQuery();
     }
     
     public int executeUpdate(String sql,ArrayList paras) throws Exception
     {
         stmt = getStatement(sql);
         if (paras != null) 
         {
        	Object o[] = paras.toArray();
            for (int i = 0; i < o.length; i++) 
            {
            	if (o[i] instanceof String) 
            	{
            		stmt.setString(i + 1, (String) o[i]);
            	}
            }
         }
         return stmt.executeUpdate();        
     }
     
     public void commit()
     {
    	 try
    	 {
    		 con.commit(); 
    	 }
    	 catch (Exception e) {}
     }
     
     public void rollback()
     {
    	 try 
    	 {
    		 con.rollback();
    	 }
    	 catch (Exception e) {}
     }
     public void close()
     {
         try
         {
        	 rs.close();
         }
         catch(Exception e){}
         try
         {
             stmt.close();
         }
         catch(Exception e){}
         try
         {
        	 con.close();
         }
         catch(Exception e){}
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -