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

📄 dbconnect.java

📁 java阿里巴巴代码
💻 JAVA
字号:
package com.saas.sys.dbm;


import java.sql.*;
import com.saas.biz.commen.config;

public class DbConnect {
	public DbConnect(){}
	/**
	public Connection getConnection() 
	{
		Connection ConnectionHandle=null;	
		
		try
		{
			//Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); 
			Class.forName("com.p6spy.engine.spy.P6SpyDriver").newInstance(); 
			String url="jdbc:oracle:thin:@192.168.10.202:1521:btob"; //orcl为数据库的SID 
			String user="web"; 
			String password="web111111"; 
			ConnectionHandle= DriverManager.getConnection(url,user,password);
			//ConnectionHandle= DriverManager.getConnection("listenerconfig=C:/Tomcat 5.0/log_sql/config.xml:url="+url,user,password);
			ConnectionHandle.setAutoCommit(false);
		}	 
	  	catch(ClassNotFoundException cnf)
	  	{
	  		throw new RuntimeException(cnf);
  		}
  		catch(SQLException sqle)
  		{
  			throw new RuntimeException(sqle);
  		}
		catch (Exception e) 
		{
			throw new RuntimeException(e);
   		}
		return ConnectionHandle;
	}
	**/
	/** 
	public Connection getConnection() 
	{
		Connection ConnectionHandle=null;	
		DataSource ds = null;
		try
		{
			Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds = (DataSource)envCtx.lookup("jdbc/btob/crm");
            ConnectionHandle = ds.getConnection();
			ConnectionHandle.setAutoCommit(false);
		}	 
  		catch(SQLException sqle)
  		{
  			throw new RuntimeException(sqle);
  		}
		catch (Exception e) 
		{
			throw new RuntimeException(e);
   		}
		return ConnectionHandle;
	}
	 **/
	/**public Connection getConnection()
    {
        String username = "root";
        String password = "111111";
        
        Connection ConnectionHandle = null;
        
        String driver =  "org.gjt.mm.mysql.Driver";//
        String link = "jdbc:mysql://192.168.10.86:3306/soft_xsaas?useUnicode=true&characterEncoding=GBK";
        try
        {
        	Class.forName(driver).newInstance();
        	ConnectionHandle = DriverManager.getConnection(link,username,password);      
        	ConnectionHandle.setAutoCommit(false);   
        }
        catch(Exception e)
        {
        	System.out.println("insert Edit error message :"+e.getMessage());
        }
        return ConnectionHandle;
    }**/
		public Connection getConnection()
    {
        config configFile= new config();
        configFile.init();
        String username = configFile.getString("mysqlbase.user");
        String password = configFile.getString("mysqlbase.password");
        
        String driver =  "org.gjt.mm.mysql.Driver";//
        String link = "jdbc:mysql://"+configFile.getString("mysqlbase.host")+":"+configFile.getString("mysqlbase.port")+"/"+configFile.getString("mysqlbase.sid")+"?useUnicode=true&characterEncoding=GBK";
        Connection ConnectionHandle = null;
        try
        {
        	Class.forName(driver).newInstance();
        	ConnectionHandle = DriverManager.getConnection(link,username,password);      
        	ConnectionHandle.setAutoCommit(false);   
        }
        catch(Exception e)
        {
        	System.out.println("insert Edit error message :"+e.getMessage());
        }
        return ConnectionHandle;
    }
}

⌨️ 快捷键说明

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