通过 JDBC 瘦驱动程序 (Domino Java) 连接 Oracle 11g 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3573861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem in connecting Oracle 11g through JDBC thin driver ( Domino Java )
提问by Ris
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 ?
我无法使用以下代码远程连接 Oracle 11 数据库。但是,如果我尝试连接安装在我的机器上的 Oracle 9 数据库,则相同的代码可以正常工作。有什么不见了 ?
( I'm not getting any error, Lotus Notes hangs )
(我没有收到任何错误,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);
}
}
回答by Ris
OK Guys, Now I'm able to connect.. Here are all possible connection string I've tried and all works,
好的伙计们,现在我可以连接了.. 这是我尝试过的所有可能的连接字符串,并且都有效,
1- "jdbc:oracle:thin:@server.cgg.com:1569:ServiceName"
2- "jdbc:oracle:thin:@//server.cgg.com:1569/ServiceName"
3- "jdbc:oracle:thin:@server.cgg.com:1569/ServiceName"
回答by subhasish sahu
Use this, syntax for JDBC URL for oracle 11 g has changed
使用这个,oracle 11 g 的 JDBC URL 的语法已经改变
<property name="url" value="jdbc:oracle:thin:@//localhost:1521/service_name" />