日期:2014-05-16  浏览次数:20436 次

JAVA数据库编程基础+源代码2
/**
 * @author 东海 陈光剑  chenguangjian 2013-4-9下午07:55:09
 * Email: universsky@126.com
 * Blog:  http://blog.sina.com.cn/universsky11
 *        http://blog.csdn.net/universsky
 */
package isword;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class getRATIO {
	
	String ip="10.137.5.61";
	String port="1521";//
	String sid="ora61";
	String userName="dduserdb";
	String passWord="IVcbs33";
	
	public getRATIO(){
		
	}
	
	public getRATIO(String  $ip,String $port,String $sid,String $userName,String $passWord ){
		ip=$ip;
		port=$port;
		sid=$sid;
		userName=$userName;
		passWord=$passWord;		
	}
	
	

	public Connection connectSYSDB(){
		
		
		String $ip="10.137.5.61";
		String $port="1521";//
		String $sid="ora61";
		String $userName="ddsysdb";
		String $passWord="IVcbs33";
		getRATIO g=new getRATIO();
		Connection con=g.getConnection($ip, $port, $sid, $userName, $passWord);
		
		return con;
		
	}
	
	public Connection connectUSERDB(){
		
		
		
		String $ip="10.137.5.61";
		String $port="1521";//
		String $sid="ora61";
		String $userName="dduserdb";
		String $passWord="IVcbs33";
		getRATIO g=new getRATIO();
		Connection con=g.getConnection($ip, $port, $sid, $userName, $passWord);
		
		return con;
		
		 
	}
	
	public Connection connectCBPDB(){
		
		String $ip="10.137.5.61";
		String $port="1521";//
		String $sid="ora61";
		String $userName="ddcbpdb";
		String $passWord="IVcbs33";
		getRATIO g=new getRATIO();
		Connection con=g.getConnection($ip, $port, $sid, $userName, $passWord);
		
		return con;
		
		 
		
	}
	

	
	public Connection getConnection(String $ip, String $port, String $sid, String $userName, String $passWord )
	{		
		String driverName="oracle.jdbc.driver.OracleDriver";// 连接oracle驱动包		
		String dbUrl="jdbc:oracle:thin:@"+$ip+":"+$port+":"+$sid+"";		
		Connection conn=null;		
	
		try {			
			Class.forName(driverName);			
			conn = DriverManager.getConnection(dbUrl, $userName, $passWord);		
			
		    } catch (ClassNotFoundException e) 
		    {			
			// TODO Auto-generated catch block			
			
		    	e.printStackTrace();	
		    	
			} catch (SQLException e) 
			{			
				// TODO Auto-generated catch block			
				e.printStackTrace();		
				
			}		
			//Connection conn;
			return conn;  
	}
	
	
	
	

	public static void main(String[] args) {
		
		getRATIO g=new getRATIO();
		//Connection con=g.getConnection($ip, $port, $sid, $userName, $passWord);
		
		Connection connectSYSDB=g.connectSYSDB();
		Connection connectCBPDB=g.connectCBPDB();
		Connection connectUSERDB=g.connectUSERDB();
		
		
		
		Statement smSYSDB = null;
		Statement smCBPDB = null;
		Statement smUSERDB= null;
		
		
		
		
		try {
			smSYSDB = connectSYSDB.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			smCBPDB = connectCBPDB.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			smUSERDB = connectUSERDB.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		ResultSet rsSYSDB=null;
		ResultSet rsCBPDB=null;
		ResultSet rsUSERDB=null;
		
		String qrySYSDB="select * from TS_PRODPRICEPLAN ";
		//String qryCBPDB="select * from ts_productorder where subscriberkey=";
		String qryCBPDB="select * from ts_productorder";
		String qryUSERDB="select * from cbe_subscriber where subscribercode=136137900";
		
		String subscriberkey=null;
		
		try {
			rsSYSDB = smSYSDB.executeQuery(qrySYSDB);
		} catch (SQLException e) {
			// TODO Auto-gener