Java连接字符串到Oracle云数据库

时间:2016-01-08 10:59:05

标签: java database oracle oracle-cloud-infrastructure-classic

从java代码连接到Oracle云数据库时遇到问题。

  • 连接其他非云oracle数据库没有问题。

  • 我可以使用sql工具连接到Oracle云数据库,但java代码除外。

  • 主机名,用户名和密码是正确的,我不会透露真实的用户名和密码。

错误:java.sql.SQLException:

SQLException: SQLState(null) vendor code(17002)
java.sql.SQLException: Io exception: Oracle Error ORA-12650: No common encryption or data integrity algorithm

我的代码如下:

String dbURL = "jdbc:oracle:thin:@192.133.133.23:1521:ORCL";

try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(dbURL, "username1", "password");


}catch(Exception)
{
  e.printStacktrace();
}

3 个答案:

答案 0 :(得分:0)

/**
 * The below one is for oracle thin client
   Its worked for the ojdbc6 driver. 
 */
public Connection conCheck() {

      Connection con=null;
      try { //step1 load the driver class
      Class.forName("oracle.jdbc.OracleDriver");

      Properties props = new Properties();
      props.put("oracle.net.encryption_client", "REQUIRED");
      props.put("oracle.net.encryption_types_client",  "( " + AnoServices.ENCRYPTION_AES256 + "," +AnoServices.ENCRYPTION_AES192 + ")");
      props.put("oracle.net.crypto_checksum_types_client", "( SHA1 )");
      props.put("user", "username");
      props.put("password","password");

    //step2 create  the connection object          
      con=DriverManager.getConnection(  "jdbc:oracle:thin:@host:port:serveiceid",props);

       System.out.println("Con"+con);
      }catch(Exception e) {e.printStackTrace(); }       

 return con;
}

答案 1 :(得分:0)

似乎将连接字符串中的语法更改为查询SERVICE_NAME而不是SID似乎必须帮助您连接数据库。

String dbURL = "jdbc:oracle:thin:@192.133.133.23:1521/ORCL";

其他阅读:Thin-style Service Name Syntax

如果这也无济于事,则建议在数据库中的sqlnet.ora中添加以下两行。

SQLNET.CRYPTO_CHECKSUM_TYPES_CLIENT= (SHA1)
SQLNET.CRYPTO_CHECKSUM_CLIENT = requested

答案 2 :(得分:0)

第一个强制检查是验证oracle jdbc版本。如果您使用的版本不兼容,我们会得到这个错误提示。