Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.sql.*;
- import oracle.jdbc.pool.*;
- public class ThinTnsnames {
- // private static OracleConnection connection = null;
- static String sql = null;
- public static void main(String[] args) {
- String entry_name = "LITPUB_RO"; //args [0];
- String userId = "cdb_reader"; // args [1];
- String password = "reader"; //args [2];
- test (entry_name, userId, password);
- }
- public static void test (String entry_name, String userId, String password) {
- Connection pconnection = null;
- try {
- System.setProperty("oracle.net.tns_admin", "/sw/common/oracle");
- // String url = "jdbc:oracle:thin:@mytns_alias";
- // Connection conn = DataSource.getConnection (url, userName, password);
- String l_url = "jdbc:oracle:thin:@" + entry_name;
- System.out.println( " Connection string = " + l_url );
- OracleDataSource ods = new OracleDataSource();
- ods.setUser(userId);
- ods.setPassword(password);
- ods.setURL(l_url);
- pconnection = ods.getConnection ();
- version (pconnection );
- }
- catch(SQLException e) {
- e.printStackTrace();
- }
- finally {
- try {
- if (pconnection != null )pconnection .close();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void version (Connection pconnection) {
- try {
- DatabaseMetaData dmd = pconnection.getMetaData();
- System.out.println("DriverVersion: ["+dmd.getDriverVersion()+"]");
- System.out.println("DriverMajorVersion: ["+dmd.getDriverMajorVersion()+"]");
- System.out.println("DriverMinorVersion: ["+dmd.getDriverMinorVersion()+"]");
- System.out.println("DriverName: ["+dmd.getDriverName()+"]");
- System.out.println("URL: ["+dmd.getURL()+"]");
- System.out.println("UserName: ["+dmd.getUserName()+"]");
- System.out.println(dmd.getDatabaseProductName() );
- System.out.println(dmd.getDatabaseProductVersion() );
- String ver;
- ver = System.getProperty("java.version");
- System.out.println("The JDK version is " + ver);
- }
- catch(SQLException e) {
- e.printStackTrace();
- }
- }
- }
- note this is the MOS example with the cmd line params embedded (System.setProperty...)
- throws this
- Connection string = jdbc:oracle:thin:@LITPUB_RO
- java.sql.SQLException: Io exception: SO Exception was generated
- at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
- at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
- at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:382)
- at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:336)
- at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:374)
- at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:150)
- at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
- at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:576)
- at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:253)
- at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:180)
- at test.ThinTnsnames.test(ThinTnsnames.java:31)
- at test.ThinTnsnames.main(ThinTnsnames.java:15)
- if I try to connect with the host:port:service name syntax it works fine
- jdbc:oracle:thin:@//ora-clu2b-vip:1541/TESTLIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement