Hello,
This is my first Java application I am creating (using Eclipse IDE) and the second Oracle based app (I'm a .NET/MSSQL guy for years). The first Oracle app I wrote in .NET did not have any issues, and I'm trying to connect to the same server.
- I have installed:
- 'Java 2 Platform, Enterprise Edition 1.4 SDK'
- 'Java DB `10.5.3.0' -'Java(TM) 6 Update 21
- 'Java(TM) SE Development Kit 6 update 21
- 'Oracle IRM Client' (11g)
- Oracle 11g Release 2 JDBC Drivers (ojdbc6.jar)
My code is very simple. Here it is:
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:oci:@");
ods.setUser("username");
ods.setPassword("password");
ods.setServerName("servername");
ods.setPortNumber(1549);
ods.setServiceName("foo.myservice.com");
Connection conn = ods.getConnection();
I get below exception:
Exception in thread "main" java.sql.SQLException: ORA-12560: TNS:protocol adapter error
at oracle.jdbc.driver.T2CConnection.checkError(T2CConnection.java:737)
at oracle.jdbc.driver.T2CConnection.logon(T2CConnection.java:401)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:531)
at oracle.jdbc.driver.T2CConnection.<init>(T2CConnection.java:148)
at oracle.jdbc.driver.T2CDriverExtension.getConnection(T2CDriverExtension.java:53)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:503)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
at Select.GetScalar(Select.java:47)
at Job.Run(Job.java:20)
at Main.main(Main.java:19)
I have google'd the hack out of this.. I've tried adding a 'TNS entry to the tnsnames.ora file'. I've tried adding '##NAMES.DIRECTORY_PATH = (TNSNAMES, EZCONNECT)' to the sqlnet.ora file. I've tried various other things but nothing is working.
Has anyone experienced this before and has any clue on how to get this to work?? Am I using the wrong version? Server is remote (I don't have Oracle server installed locally, just client). Maybe I have wrong version of Java SDK or the wrong version of the JDBC .jar file?? I just need to connect to Oracle and run a single simple query! Thanks much for any help.