简体   繁体   English

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

[英]Java Connection String to Oracle Cloud Database

I had problem when connecting to Oracle Cloud Database from java code.从 java 代码连接到 Oracle 云数据库时遇到问题。

  • I have no problem connecting other non-cloud oracle databases.我连接其他非云oracle数据库没有问题。

  • I can connect to the Oracle Cloud Database with sql tools, except from the java codes.我可以使用 sql 工具连接到 Oracle 云数据库,除了 java 代码。

  • The hostname, username and password is correct one, i don't reveal the real username and password.主机名,用户名和密码是正确的,我不透露真实的用户名和密码。

Error: java.sql.SQLException:错误: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

My code as following:我的代码如下:

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();
}
/**
 * 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;
}

Seems like changing syntax in your connection string to lookup SERVICE_NAME instead of SID must help you connect your database.似乎更改连接字符串中的语法以查找SERVICE_NAME而不是SID必须帮助您连接数据库。

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

Additional Read : Thin-style Service Name Syntax补充阅读: 精简式服务名称语法

If this as well doesn't help, then would suggest to add below 2 lines to your sqlnet.ora in database.如果这也没有帮助,那么建议在数据库中的 sqlnet.ora 中添加以下 2 行。

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

First mandatory check is to verify the oracle jdbc version.第一个强制检查是验证oracle jdbc 版本。 if you use incompatible version,we will get this kid of errors.如果你使用不兼容的版本,我们会得到这个错误的孩子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM