• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loading Oracle JDBC Driver

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone tell me how to load the driver for JDBC for an Oracle database, or give me a tutorial link. I can't seem to load drivers.
Reilly
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Class.forName(driverName);
This will load the Driver.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Warning -- Danger Will Robinson!
Don't try to load a Driver with the DriverManager class if you are working in an EJB container. Instead, set up a DataSource using the tools provided by your container vendor and use the DataSource to obtain connections. If you use a DriverManager the database driver's connections will NOT be enlisted in EJB transactions...
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running Oracle8 and JDK1.3.1_01. What drivers should I be using, and where might I find the name of it in my directories... I have been running this code:
import java.sql.*;
import java.math.*;
class testJDBC
{
public static void main(String []args)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@mydatabase", "scott", "tiger");
String createTableCoffees = "CREATE TABLE COFFEES " +
"(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " +
"SALES INTEGER, TOTAL INTEGER)";

Statement stmt = conn.createStatement();
stmt.executeUpdate(createTableCoffees);
}// *********end try
catch (Exception e)
{
e.printStackTrace();
}//**********end catch
}//**********end main
}//**********end class
Is " @mydatabase" the correct syntax, and if not, where do if find the name of my database? I keep getting the error:
java.lang.ClassNotFoundException:oracle.jdbc.driver.OracleDriver with an associated stack of errors.
If anybody can help out here, I could really use a hand. All I want to do is write to this Oracle DB.
Reilly
(Editted by Dave to get rid of the smilies)
[This message has been edited by David O'Meara (edited November 14, 2001).]
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This doesn't seem like an EJB question but rather a JDBC question. I am moving this to the JDBC forum where you will get better responses.
------------------
Tom
Sun Certified Programmer for the Java� 2 Platform
Moderator of the forums:
J2EE and EJB
Other Java APIs
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would verify that the Oracle driver (e.g. classes12.zip)is located somewhere in your classpath.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is their a reason why you are using the OCI8 drivers(like security, firewalls, encryption...)? Otherwise, I would definitely use the thin driver. Seems like you are just starting out so I'll list you a complete set of Oracle/jdbc/java resource links. These links should get you well on your way:
These should be all the Oracle resources you need to get started, get familiar with jdbc, trouble shoot your problems, and eventually become advanced!
download your oracle drivers at http://technet.oracle.com/software/tech/java/sqlj_jdbc/content.html and follow the download procedures
enable the client to connect(set environment) http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/java.817/a83728/05confi3.htm#1003460
To find all the Oracle specific code that you could ever need http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/content.html -->look for the "JDBC Samples" links
If you just want code snippets that explain various tasks, this is a good link too:
http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/htdocs/templates.htm
if you come accross a problem, check this list before you post here:
http://otn.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm
if you come accross an Oracle SQLException, then you can investigate the ORA-XXXXX error messages and solutions at:
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a76999/toc.htm
good luck,
Jamie
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot Jamie! Looks like I have some work to do. Didn't want anyone to solve it for me... just wanted some research resources to do it myself!
Thanks again,
Reilly
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your welcome! took me a while to find these, but now I use them all the time. 90% of my answers to posts come from these links! If you come across any roadblocks, let us know.
Jamie
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again...
Okay, I have the correct driver. Now when I try to create a connection, it keeps throwing an SQL Exception but it is because I am not configuring the JDBC URL correctly. The Thin driver syntax should follow:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@<mc-name>:<port-no>:<sid>","scott", "tiger");
What is <mc-name>,<port-no> and <sid>, and how would I find out what they are specifically on my local machine. I have no experience with Oracle other than what I have managed to do so far with it in JDBC, and as you can see I am having troubles.
Whatever you could volunteer would be great.
Reilly- tired and Oracled out (all I want to do is write Java!)
(Editted by Dave to fix smilies and angle brackets)
[This message has been edited by David O'Meara (edited November 14, 2001).]
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again...
Okay, I have the correct driver. Now when I try to create a connection, it keeps throwing an SQL Exception but it is because I am not configuring the JDBC URL correctly. The Thin driver syntax should follow:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@mcname:port:sid","scott", "tiger");
What is mcname, port and sid, and how would I find out what they are specifically on my local machine? I have no experience with Oracle other than what I have managed to do so far with it in JDBC, and as you can see I am having troubles.
Whatever you could volunteer would be great.
Reilly- tired and Oracled out (all I want to do is write Java!)
(Editted by Dave to fix those damn smilies)
[This message has been edited by David O'Meara (edited November 14, 2001).]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you may not have to use all the parameters that are specified since it is on your local machine. Usually Oracle is running on a separate server, so you would need to know the domain name/IP address, port number and instance name. Since it is local my guess would be to just use the instance name(name of the database)
I would guess this:
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@sid","scott", "tiger");
I have also found this technique on google.com:
DriverManager.getConnection("jdbc:oracle:thin:scott/tiger");
I have also seen this:
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:yourDBname","scott","tiger");
So try em out, and see if it works. What is the Exception that is being thrown and what is the URL that you are trying now?

Jamie
those damn smilies again! can they have a default of being off for this specific forum?

[This message has been edited by Jamie Robertson (edited November 15, 2001).]
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code I am using, just trying to make a connection and when I java it, it throws the exception:
class jdbcPract
{
public static void main(String []args)
{
try
{
//register the driver (this compiles fine)
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver ());
//create connection (once I added this exceptions began)
Connection conn = DriverManager.getConnection("jdbc: oracle:thin:@127.0.0.1:1521: oracle","scott","tiger");
//Just create a statement
Statement stmt = conn.createStatement();
//Close the "existing" connection(which has yet to happen:) )
conn.close();
}//try
catch(Exception e)
{
System.out.println(e);
}//catch
}//main
}
The code is simply meant to load the driver, then create a connection, then a statement, then close the connection. I didn't want to get into ResultSet creation and trying to send data to the db before I figure out how to get a viable connection. Anyway, the above code throws:
java.sql.SQLException: 20
I could find nothing on Google about this error or what it indicates. I have tried all three of your options with the same error. I have spent the last three days getting the driver to load, which seems to work fine now. But now creating this connection is causing more problems. I am reading Java Enterprise in a Nutshell (O'Reilly), and it makes this look so easy on paper.
Reilly
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More specifically...
java.sql.SQLException: 20
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:407)
at oracle.jdbc.driver.OracleConnection.<init>OracleConnection.java:152)
at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:214)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:193)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at jdbcPract.main(jdbcPract.java:20)
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jamie Robertson:
those damn smilies again! can they have a default of being off for this specific forum?


When you create a post you can check the "Disable Smilies in This Post." checkbox, but otherwise the answer is "No, not really". We've tried a few solutions with the UBB software that Javaranch runs on but no luck so far.
It isn't such a problem in other forums so I guess we'll just have to make do here in the JDBC forum
Dave.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to capture more useful information on the error try this error catching technique:

I'm going to guess that maybe you don't have permissions for the user "scott" with password "tiger". To ensure that you can use this combination, open a SQL*Plus session using "oracle" as the database and scott and tiger as the username/password combination.
Jamie
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also noticed an extra space in your connection url just before your database name:
Connection conn = DriverManager.getConnection("jdbc: oracle:thin:@127.0.0.1:1521: oracle","scott","tiger");
by the way, did you name your database "oracle"? Just wondering, I don't want you to think that the field is for the database vendor name. If you create a "payroll" database then you should use
Connection conn = DriverManager.getConnection("jdbc: oracle:thin:@127.0.0.1:1521:payroll","scott","tiger");
Jamie
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, the spaces were there to avoid the smilies, and the name of the db is oracle. So other than that, I think I had the syntax correct. I have permissions, firstly it's Oracle personal I jsut installed, and I verified through the SQL*Plus tool. So other than that, I don't know how to proceed. This really does not appear to be that difficult, or at least it shouldn't be. I will try the Exception message method you provided.
Chat later,
Reilly
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
there is a little checkbox labeled "Disable Smilies in This Post" that you can check so that you don't have to throw in extra spaces. Anyways, post the error message that you get using the new try/catch procedure I showed you. "20" isn't a very useful error message to work with. You should get "ORA-99999 - some error message" followed by the Stack Trace. This will be much more helpful in telling you what your error is.
Jamie
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any luck Reilly? or did you put the project on hold for the time being?
 
Reilly Morris
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jamie,
Actually, I have just got the Oracle 8i complete reference from Oracel Press. There is a complete section on JDBC configuration, which I will cover tonight. I will let you know how it works out. I still think it is somewhere in the Connection params.
Chat soon,
Reilly
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I will try the Exception message method you provided.


you never did inform us as to what the ORA-XXXXX error number/message was using the getMessage() in your catch block. This can be very helpful in diagnosing the exact problem.
try to post this ASAP so we can help rid you of this problem!
Jamie
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic