展开全部
public class DBConnection {
/**
* 获取数据连接
* */
public static Connection getConnection(String ip,String port,String sid,String userName,String passWord ){
String driverName="oracle.jdbc.driver.OracleDriver";
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();
}
return conn;
}
}
/**
* 获取数据连接
* */
public static Connection getConnection(String ip,String port,String sid,String userName,String passWord ){
String driverName="oracle.jdbc.driver.OracleDriver";
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();
}
return conn;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
驱动:oracle.jdbc.driver.OracleDriver
URL:jdbc:oracle:thin:@<machine_name><:port>:dbname
jdbc:oracle:thin:@localhost:1521:orcl
注:machine_name:数据库所在的机器的名称;
port:端口号,默认是1521
username:默认是scott
password:默认是tiger
URL:jdbc:oracle:thin:@<machine_name><:port>:dbname
jdbc:oracle:thin:@localhost:1521:orcl
注:machine_name:数据库所在的机器的名称;
port:端口号,默认是1521
username:默认是scott
password:默认是tiger
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询