aspose file tools*
The moose likes JDBC 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "newbie to both java and oracle.. how do i ..." Watch "newbie to both java and oracle.. how do i ..." New topic
Author

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

Kevin Rauer
Greenhorn

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)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e)
{
logError("Error: Failed to load JDBC DBC Driver!");
}
try
{

DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver()) ;
Connection con = DriverManager.getConnection("jdbc dbc:thin:@172.25.5.70:1521:aixedev","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
Bartender

Joined: Oct 29, 2001
Posts: 8705
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Kevin Rauer
Greenhorn

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
Greenhorn

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

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 http://www.codefutures.com/firestorm
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie to both java and oracle.. how do i ...
 
Similar Threads
ATG oracle thin problem
problem in connecting to oracle through jdbc
Connecting to MSSQL2000
New to jdbc,please help
cannot connect to oracle using datadirect JDBC driver