File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Newbie: How doy I connect to Oracle Using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Newbie: How doy I connect to Oracle Using JDBC" Watch "Newbie: How doy I connect to Oracle Using JDBC" New topic
Author

Newbie: How doy I connect to Oracle Using JDBC

Fernando Caceres
Greenhorn

Joined: Dec 02, 2002
Posts: 5
The next code tells me that ->
" Invalid Oracle URL specified: OracleDriver.connect"
import java.sql.*;
What is wrong???
Please help!!!

[ Edited by Dave to remove smilies and format code ]
[ December 02, 2002: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"TGO",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
Third post I found today that has the same problem. (One DB2, One mySQL, now one Oracle).
Doesn't look like you are registering the driver. Only loading the class. Try

The above code works if you import oracle.jdbc.driver.*. If you just put classes12.zip or classes2.zip onto the class path, you will need to do Class.forName().newInstance() and cast that to a Driver.
If you don't register the driver, there is no point in creating an instance of the object.
Also, you might want to declare your Connection variable outside of the try block. So if you catch an error, you will be able to close the connection cleanly in the catch block.
[ December 02, 2002: Message edited by: Michael Zalewski ]
[ December 02, 2002: Message edited by: Michael Zalewski ]
Fernando Caceres
Greenhorn

Joined: Dec 02, 2002
Posts: 5
Thanks for the help but now tells me 'ORA-06401: NETCMN: invalid driver designator'
what is wrong?
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
OCI is not installed on your webserver. Or it's not properly installed.
Try using the thin client first
Fernando Caceres
Greenhorn

Joined: Dec 02, 2002
Posts: 5
Thanks It Works
Fernando Caceres
Greenhorn

Joined: Dec 02, 2002
Posts: 5
It's working, but this was a connection to a Oracle DB that wasn't (SERVER=DEDICATED) in my TNSNAMES.ORA . NOW I want to connect to a Oracle DB with (SERVER=DEDICATED) but throws this message 'Io exception: The Network Adapter could not establish the connection' , always using JDBC and applets
Fernando Caceres
Greenhorn

Joined: Dec 02, 2002
Posts: 5
I found it:
String url1 = "jdbc racle:thin:@(DESCRIPTION = " +
" (ADDRESS_LIST =" +
" (ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.4)(PORT = 1521)))" +
" (CONNECT_DATA = " +
" (SID = ORCL) " +
" (SERVER = DEDICATED) ))";

Connection conn =
DriverManager.getConnection (url1, "uid", "pwd");
.....
This works...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Newbie: How doy I connect to Oracle Using JDBC