Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes newbie to both java and oracle.. how do i ... 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 "newbie to both java and oracle.. how do i ..." Watch "newbie to both java and oracle.. how do i ..." New topic

newbie to both java and oracle.. how do i ...

Kevin Rauer

Joined: Oct 31, 2003
Posts: 3
I am trying to write a java program to connect to an Oracle server and return a record set..
I keep getting the following error..
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified..
here is the code I am trying to get to work..
import oracle.sql.*;
import oracle.jdbc.driver.*;
protected void loadTestDataDB(ArrayList CIFList)
catch (ClassNotFoundException e)
logError("Error: Failed to load JDBC DBC Driver!");

DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver()) ;
Connection con = DriverManager.getConnection("jdbc dbc:thin:@","user","password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM agents");
... etc
What am I doung wrong.. the oracle client is installed on the machine and i can connect to the above with sqlplus..
Any help would be apreciated..
Joe Ess

Joined: Oct 29, 2001
Posts: 9167

Get rid of the try-catch block where you register sun.jdbc.odbc.JdbcOdbcDriver. You don't need ODBC to connect to Oracle, and if you wanted to use it, you obviously haven't set up an ODBC data source to do so. The rest should work as is.

[How To Ask Questions On JavaRanch]
Kevin Rauer

Joined: Oct 31, 2003
Posts: 3
I just want to connect to the oracle database.. if I don't have to use odbc then thats fine..
could you give me a code example to just return a recordset from an oracle database..
Thanks in advance
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
You are almost there. Try this:

When you do a "Class.forName(...)" on a JDBC driver (such as the oracle thin driver), it will automatically register the driver with the DriverManager class. Also, the URL for the thin driver starts out "jdbcracle:thin", not "jdbcdbc:thin".
It's a very good idea to close all of your database resources (connection, statement, resultset) in a "finally{ }" block to make sure they are closed regardless of what happens in the try/catch sections of the code. There is no need to import any of the "oracle.*" classes.
As Joe pointed out, there is no need to use the jdbcdbc driver and, in fact, with the thin driver (type 4) it's not necessary to have the Oracle client installed at all. So you can run on any machine as long as you have the thin driver jar/zip file installed.
[ November 11, 2003: Message edited by: Wayne L Johnson ]
Kevin Rauer

Joined: Oct 31, 2003
Posts: 3
Thanks a Million..
Andy Grove

Joined: Nov 11, 2003
Posts: 18
I'd recommend downloading a free trial of our FireStorm/DAO product - you can point it at a database schema and have it generate complete Java/JDBC code for insert/update/delete and query operations for your tables. It's a great way to learn about the best way to write this sort of code. It also generates a ResourceManager utility class for creating/destroying connections.
More info at
I agree. Here's the link:
subject: newbie to both java and oracle.. how do i ...
It's not a secret anymore!