Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie: How doy I connect to Oracle Using JDBC

 
Fernando Caceres
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help but now tells me 'ORA-06401: NETCMN: invalid driver designator'
what is wrong?
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OCI is not installed on your webserver. Or it's not properly installed.
Try using the thin client first
 
Fernando Caceres
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks It Works
 
Fernando Caceres
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic