It's not a secret anymore!*
The moose likes JDBC and the fly likes Stored Procedure java code error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Stored Procedure java code error" Watch "Stored Procedure java code error" New topic
Author

Stored Procedure java code error

Srikanth Ravuri
Greenhorn

Joined: Jan 26, 2011
Posts: 12
Hi

I am new to java. I am trying to call data from Oracle using java code but got few errors. Can you please help me where I am going wrong.

Thanks in advance.

Code:





Error:

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.srikanth.bank.dao.EmpDAO.main(EmpDAO.java:19)
java.sql.SQLException: No suitable driver found for jdbc:oracle:thin @localhost:1521:XE
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.srikanth.bank.dao.EmpDAO.main(EmpDAO.java:29)



Please help me where I am going wrong.

Anand Bhatt
Ranch Hand

Joined: May 30, 2007
Posts: 189
Do you have classes12.jar file in your application path?
Srikanth Ravuri
Greenhorn

Joined: Jan 26, 2011
Posts: 12
Anand Bhatt wrote:Do you have classes12.jar file in your application path?


Thanks Anand for the reply.

I am new to java. I am using eclipse to call the stored procedures. As you said I downloaded classes12.jar file and uploaded my java lib folder and still I couldn't see that on eclipse. Any suggestion of where I am doing the mistake.

Please help.

Thank you,
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
Welcome to JavaRanch

Please always put code in code tags (Since you are new I have edited your post and you can see how much better it looks) and indent your code correctly.

If you didn't update your classpath for the project on Eclipse®, that .jar will be invisible to your application. I am not quite sure how to do it, but try
  • right-click project name
  • import
  • General
  • Archive File
  • Browse for file
  • Import into a folder
  • Can't promise that will work. You should be able to find some sort of help or tutorial for Eclipse┬« which will help you.
    Tom Reilly
    Rancher

    Joined: Jun 01, 2010
    Posts: 618
    Actually, it's:
    1. Right click on the project
    2. Select Properties
    3. Select Java Build Path
    4. Select the Libraries tab
    5. Click the Add External JARs button
    6. Navigate to, and select classes12.jar
    Srikanth Ravuri
    Greenhorn

    Joined: Jan 26, 2011
    Posts: 12
    Tom Reilly wrote:Actually, it's:
    1. Right click on the project
    2. Select Properties
    3. Select Java Build Path
    4. Select the Libraries tab
    5. Click the Add External JARs button
    6. Navigate to, and select classes12.jar


    Thank you Tom

    I got hold up with DB connectivity error saying:


    any suggestion at to keep me on a right track.

    Thank you
    Anand Bhatt
    Ranch Hand

    Joined: May 30, 2007
    Posts: 189
    You are on track now:

    This error is thrown if a user wants to log on a database but lacks the create session system privilege.
    In order to give someone this privilege, use:
    grant create session to the_user;
    Srikanth Ravuri
    Greenhorn

    Joined: Jan 26, 2011
    Posts: 12
    Anand Bhatt wrote:You are on track now:

    This error is thrown if a user wants to log on a database but lacks the create session system privilege.
    In order to give someone this privilege, use:
    grant create session to the_user;


    Thanks Anand for quick response.

    I have a new problem now. I can print 1st row of the data and the rest it stops with an error message





    Here is my new java code.




    Any comments or suggestions on where I went wrong.

    Thank you,

    Tom Reilly
    Rancher

    Joined: Jun 01, 2010
    Posts: 618
    A few comments:
    1. You only get back one set of output parameters. Your code suggests that you expect multiple sets because you attempt to get them in a loop.

    2. Here's a link to some Oracle documentation. It says:
    After all values have been retrieved from ResultSet objects (using ResultSet.getXXX methods), and after it has been determined that there are no more update counts, values from OUT parameters can be retrieved (using CallableStatement.getXXX methods).

    3. Despite the comment in the code that says "close the connection", you are not closing your connection. Do you see the error?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Stored Procedure java code error
     
    Similar Threads
    Problems with Callable Statement in Sybase
    How can get the return code of a StoreProcedure?
    Stoared procedure & Type 4 driver
    Confused by Stored Procedure Error
    current transaction is aborted, queries ignored until end of transaction block