通过JDBC瘦驱动程序(Domino Java)连接Oracle 11g时出现问题

时间:2010-08-26 09:40:37

标签: java jdbc lotus-notes oracle11g

我无法使用以下代码远程连接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);
  }
}

3 个答案:

答案 0 :(得分:2)

好的伙计们,现在我能够连接..以下是我尝试过的所有可能的连接字符串,并且一切正常,

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"

答案 1 :(得分:1)

我刚才偶然发现了这篇文章,试一试:Oracle SID != SERVICE_NAME

答案 2 :(得分:0)

使用此,oracle 11 g的JDBC URL语法已更改

<property name="url" value="jdbc:oracle:thin:@//localhost:1521/service_name" />