File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Oracle10g: java.sql.SQLException: Invalid Oracle URL specified Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Oracle10g: java.sql.SQLException: Invalid Oracle URL specified" Watch "Oracle10g: java.sql.SQLException: Invalid Oracle URL specified" New topic

Oracle10g: java.sql.SQLException: Invalid Oracle URL specified

Deepak Kumar
Ranch Hand

Joined: Nov 05, 2007
Posts: 62
Hi All,

I am using the below code but I am unable to connect to the database. Its throwing an error "Invalid Oracle URL specified"

DB: oracle 10g
OS: Windows Vista
jar : ojdbc14.jar

Below is the code, please help me

and below is the error I get

Is there anything I am missing ??? Please help me out.

the contents of my listener.ora file is

(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
(PROGRAM = extproc)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\10.2.0\server)
(PROGRAM = extproc)

(ADDRESS = (PROTOCOL = TCP)(HOST = Deepak-PC)(PORT = 1521))


Thanks a lot,

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33119

Are you able to connect to the "XE" database SID from the command line? This will rule out Java and let you focus on the database configuration part.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Deepak Kumar
Ranch Hand

Joined: Nov 05, 2007
Posts: 62

yeah, I am able to connect to DB from cmd line successfully

Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147

I don't know about the URL syntax or if this is helpful, but where is the username password?
The OracleDataSource() API states this for setUrl(String):
Set the URL from which connections have to be obtained. If URL is set all other properties like databasename, servername, portNumber, network protocol, tnsentry, and driver Type will be ignored.

The API also states
A JDBC driver that is accessed via the DataSource API does not automatically register itself with the DriverManager.

Which I think means you would need to explicitly call setDriverType(String) on the "ods" reference.

So I suspect even if you have it in listener.ora, it will not be used when using this method of getting a connection.
Maybe you need to set some additional connect properties when using Oracle driver API direct method of connecting as proposed to using the DriverManager or JNDI?
Steven Schwab

Joined: May 25, 2010
Posts: 9
I think you need to remove a line of code. Lines 31-32 (34-35 in your actual source, according to your stack trace), you have:

The error you are getting is on the call to defaultConnection():

Remove line 31 (conn = new oracle.jdbc.OracleDriver().defaultConnection();) and tell us what happens. I think you just want ods.getConnection() since you've configured ods with your Oracle URL.
I agree. Here's the link:
subject: Oracle10g: java.sql.SQLException: Invalid Oracle URL specified
It's not a secret anymore!