通过 JDBC 瘦驱动程序连接 Oracle 11g 时出现问题 (Domino Java)
我无法使用以下代码远程连接 Oracle 11 数据库。但是,如果我尝试连接安装在我的计算机上的 Oracle 9 数据库,相同的代码可以正常工作。缺什么 ?
(我没有收到任何错误,Lotus Notes 挂起)
import lotus.domino.*;
import java.sql.*;
import oracle.jdbc.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
//Calling connection method
Connection conn= getOracleConnection(db);
if(conn!=null){
System.out.println("Connected..");
}
else {
System.out.println("There is a problem in connecting database..");
System.exit(0);
}
} catch(Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private static Connection getOracleConnection(Database db) throws Exception {
// Register driver
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
//Retrieving connection string from profile document.
String host = "SPRPRG020.int.server.com";
String ip = "1521";
String user = "system";
String password = "password";
String sid = "XE";
String url="jdbc:oracle:thin:@"+host+":"+ip+":"+sid;
return DriverManager.getConnection(url, user, password);
}
}
I'm unable to connect Oracle 11 database remotely using following piece of code. However, same code works fine if I try to connect Oracle 9 database which is installed on my machine. What is missing ?
( I'm not getting any error, Lotus Notes hangs )
import lotus.domino.*;
import java.sql.*;
import oracle.jdbc.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
//Calling connection method
Connection conn= getOracleConnection(db);
if(conn!=null){
System.out.println("Connected..");
}
else {
System.out.println("There is a problem in connecting database..");
System.exit(0);
}
} catch(Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private static Connection getOracleConnection(Database db) throws Exception {
// Register driver
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
//Retrieving connection string from profile document.
String host = "SPRPRG020.int.server.com";
String ip = "1521";
String user = "system";
String password = "password";
String sid = "XE";
String url="jdbc:oracle:thin:@"+host+":"+ip+":"+sid;
return DriverManager.getConnection(url, user, password);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,现在我可以连接了..以下是我尝试过的所有可能的连接字符串,并且都有效,
OK Guys, Now I'm able to connect.. Here are all possible connection string I've tried and all works,
使用这个,oracle 11 g 的 JDBC URL 语法已更改
Use this, syntax for JDBC URL for oracle 11 g has changed