import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class ConnPOP {
java.util.Properties prop = new java.util.Properties();
/*TaiWan Operation Server*/
String DbSID = "TEST";
String HostName = "192.168.1.20";
String username = "TEST";
String userpwd = "TEST";
//REMOTE ORACLE 8i THIN
String url = "jdbc:oracle:thin:@"+ HostName + ":1521:" + DbSID;
Connection conDB = null;
public Connection getConn(){
try{
prop.put("user", username);
prop.put("password", userpwd);
prop.put("CHARSET", "eucksc");
// Oracle 8i not pooling connection
Class.forName("oracle.jdbc.driver.OracleDriver");
//取得連線
conDB = DriverManager.getConnection(url, username, userpwd);
//System.out.println("DataBase connected : " + conDB.toString());
System.out.println("DataBase connected ");
conDB.setAutoCommit(false);
}
catch(ClassNotFoundException cnfe){
System.out.println("Driver didn't be load : " + cnfe.toString());
}
catch(SQLException sqle){
System.out.println("DataBase didn't connected : " + sqle.toString());
}
finally{
if(conDB == null){
try{
conDB.close(); //關閉資料庫連結
}
catch(SQLException sqle){ }
}
}
return conDB;
}
//==KOREA POP
public Connection getConnKor(){
try{
prop.put("user", "TEST");
prop.put("password", "TEST");
prop.put("CHARSET", "eucksc");
// Oracle 8i not pooling connection
Class.forName("oracle.jdbc.driver.OracleDriver");
//取得連線
conDB = DriverManager.getConnection("jdbc:oracle:thin:@192.168.2.20:1521:TEST", "TEST", "TEST");
//System.out.println("KOREA DataBase connected : " + conDB.toString());
System.out.println("KOREA DataBase connected ");
conDB.setAutoCommit(false);
}
catch(ClassNotFoundException cnfe){
System.out.println("Driver didn't be load : " + cnfe.toString());
}
catch(SQLException sqle){
System.out.println("Kor DataBase didn't connected : " + sqle.toString());
}
finally{
if(conDB == null){
try{
conDB.close(); //關閉資料庫連結
}
catch(SQLException sqle){ }
}
}
return conDB;
}
}
留言列表