ITPub博客

首页 > 数据库 > Oracle > wallet和jdbc关联

wallet和jdbc关联

原创 Oracle 作者:cdshrewd 时间:2016-04-07 14:01:09 0 删除 编辑
通过wallet和jdbc关联,可以做到修改数据库密码后只需要在wallet中修改一下认证即可,应用程序代码可以不调整,只不过jdbc除了要ojdbc6.jar包外,还需要oraclepki.jar包。
以下是我的测试结果:
[oracle@pure11g admin]$ mkstore -wrl /u01/app/oracle/product/11.2.0.4/db_1/network/admin/wallet -createCredential \(DESCRIPTION=\(ADDRESS=\(PROTOCOL=tcp\)\(HOST=192.168.2.20\)\(PORT=1521\)\)\(CONNECT_DATA=\(SERVICE_NAME=oradb\)\)\) TEST test
Oracle Secret Store Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:             
  
Create credential oracle.security.client.connect_string2
[oracle@pure11g admin]$ mkstore -wrl $ORACLE_HOME/network/admin/wallet -listCredential
Oracle Secret Store Tool : Version 11.2.0.4.0 - Production
Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:             
  
List credential (index: connect_string username)
2: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.20)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oradb))) TEST
1: ORADB_SYSTEM system
[oracle@pure11g admin]$ vi Class2.java
import java.sql.*;
import java.util.Properties;
import oracle.jdbc.pool.OracleDataSource;
public class Class2 {
public static void main(String[] args) throws SQLException {

DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
String url = "jdbc:oracle:thin:/@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.20)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oradb)))";
Properties props = new Properties();
Connection conn = DriverManager.getConnection(url,props);
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery(
"select 'Connected as ' || user from user_users");
while (rset.next())
System.out.println(rset.getString(1));
rset.close();
stmt.close();
conn.close(); }
}
"Class2.java" [New] 23L, 707C written                        
[oracle@pure11g admin]$ which java
/usr/java/jdk1.6.0_21/bin/java
[oracle@pure11g admin]$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)
[oracle@pure11g admin]$ export JAVA_HOME=/usr/java/jdk1.6.0_21        
[oracle@pure11g admin]$ $JAVA_HOME/bin/javac -cp $ORACLE_HOME/jdbc/lib/ojdbc6.jar:$ORACLE_HOME/jlib/oraclepki.jar:. Class2.java
[oracle@pure11g admin]$ pwd
/u01/app/oracle/product/11.2.0.4/db_1/network/admin
[oracle@pure11g admin]$  $JAVA_HOME/bin/java -cp $ORACLE_HOME/jdbc/lib/ojdbc6.jar:$ORACLE_HOME/jlib/oraclepki.jar:. -Doracle.net.wallet_location=/u01/app/oracle/product/11.2.0.4/db_1/network/admin/wallet Class2
Connected as TEST    <------这里说明已经连接成功。
[oracle@pure11g admin]$
由于weblogic我没有环境,但是我估计只需要将连接串设置为:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.2.20)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=oradb)))
用户名和密码留空,应该就可以了

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/20502651/viewspace-2076775/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2011-12-29

  • 博文量
    5
  • 访问量
    3091