Connections between java and oracle

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ragonz
    New Member
    • Jul 2008
    • 24

    Connections between java and oracle

    Hy, i want to use oracle as my database in my java project. But, i don't know how to make connections between java and oracle.

    Can anyone give me an example for this case. Let's say i want to display the result of query "select * from tab" through java

    I'm using oracle 10.g

    Thx n advance
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    If I'm not mistaken Oracle comes with a JDBC driver; the Java side of this driver
    is part of the SE distribution. Read all about it in the API documentation.

    kind regards,

    Jos

    Comment

    • ragonz
      New Member
      • Jul 2008
      • 24

      #3
      K, here's what i've tried
      Code:
      import java.sql.*;
      
      class TestOCIApp {
      
      	public void main(String args[]) throws ClassNotFoundException, SQLException {
      
      		Class.forName("oracle.jdbc.driver.OracleDriver");
      
      
      
      		Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:@","ragonz","1234");
      
      		Statement stmt = conn.createStatement( );
      
      		ResultSet rset = stmt.executeQuery("select * from tab");
      
      		while(rset.next( ))
      
      			System.out.println(rset.getString(1));
      
      			rset.close( );
      
      			stmt.close( );
      
      			conn.close( );
      
      	}
      
      }
      but when i compiled it, it shows errors like this, n i don't know why.
      Code:
      Exception in thread "main" 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.ClassLoader.loadClassInternal(Unknown Source)
      
      	at java.lang.Class.forName0(Native Method)
      
      	at java.lang.Class.forName(Unknown Source)
      
      	at TestOCIApp.main(TestOCIApp.java:5)
      Anyone have an idea for this case?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by ragonz
        Anyone have an idea for this case?
        Yes, it can't find your Oracle JDBC driver, just as it said. You have to make that
        class available by putting the jar where it can be found in the classspath.

        kind regards,

        Jos

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Do you have the .jar file for that oracle driver? If you do then you need to include it in your program's classpath.

          Comment

          • ragonz
            New Member
            • Jul 2008
            • 24

            #6
            I'm so sorry, i'm pretty newbie with this. what .jar file did u guys mean? and how to inlcude it in my program's classpath.

            Pretty confused here....

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              If you are new to this then I suggest that you take a step back and start by reading Sun's JDBC tutorial.
              P.S The .jar file we are talking about is the oracle driver that you are trying to use. It is shipped with your installation of oracle.

              Comment

              • karthickkuchanur
                New Member
                • Dec 2007
                • 156

                #8
                just put the jar files ojdbc14.jar in lib directories of ur java path

                Comment

                Working...