📄 dbconnection.java
字号:
/********************************************************************
*
* $RCSfile: DBConnection.java,v $ $Revision: 1.1 $ $Date: 2003/09/22 08:06:24 $
*
* $Log: DBConnection.java,v $
* Revision 1.1 2003/09/22 08:06:24 icestone
* init
*
*
*
**********************************************************************/
package pcdmupgradedata;
/**
* <p>Title: 数据库连接类</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003/05/23</p>
* <p>Company: </p>
* @author Peter
* @version 1.0
*/
import java.sql.*;
public class DBConnection {
private String strIP = null; //数据库IP地址
private String strSID = null; //SID
private String strUser = null; //用户名
private String strPassword = null; //密码
public DBConnection() {
}
public void setConnectString(String strIP,String strSID,String strUser,String strPassword){
this.strIP = strIP;
this.strSID = strSID;
this.strUser = strUser;
this.strPassword = strPassword;
}
public Connection getConnection(){
//获取数据库连接对象
Connection conn = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e) {
System.out.println("Can't find class oracle.jdbc.driver.OracleDriver");
System.exit(1);
}
try {
conn = DriverManager.getConnection(
"jdbc:oracle:thin:@" + strIP + ":1521:" + strSID,strUser,strPassword);
}
catch(SQLException e) {
System.out.println("SQL error: " + e.toString());
}
return conn;
}
public void closeConnection(Connection conn){
//关闭数据库连接
if (conn != null)
try {conn.close();} catch(SQLException ignore) {}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -