Results 1 to 10 of 10
  1. #1
    freddy000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default cannot connect to oracle DB

    I'm trying to connect to an oracle data base from my netbean's application ,
    I've already added the jdbc to the library
    I've wrote the appropriate code but it's not working
    here's the code
    Java Code:
    package connection;
    import java.sql.DriverManager;
    import java.sql.Connection;
    import java.sql.*;
    public class connection {
                    public static void main(String[] args) throws SQLException{
    		try{
    			Class.forName("oracle.jdbc.OracleDriver");
    
    	              	System.out.println("Chargement du driver jdbc ds la JVM réussie");
    	
              	        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:GLOBAL","SYSTEM", "manager");
    	
            		System.out.println("Connexion réussite");
    		
                     	Statement stmtCode = con.createStatement();
               
                            ResultSet rs = stmtCode.executeQuery("select note1,note2 from T2");
    
    			while(rs.next())
                          
                            System.out.println(rs.getFloat(1) + "  " +    rs.getFloat(2));
          
                            rs.close();
    			}
                            catch(Exception e)
    	{
    				e.printStackTrace();
    			}
    	}
    }
    and here's the output message
    Java Code:
    run:
    Chargement du driver jdbc ds la JVM réussie
    java.lang.ArrayIndexOutOfBoundsException: 4
            at oracle.jdbc.driver.T4C8TTIdty.<init>(T4C8TTIdty.java:479)
            at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1113)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:308)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:536)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:228)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
            at java.sql.DriverManager.getConnection(DriverManager.java:582)
            at java.sql.DriverManager.getConnection(DriverManager.java:185)
            at connection.connection.main(connection.java:12)
    BUILD SUCCESSFUL (total time: 3 seconds)

    Any help would be appreciated, thanks.

  2. #2
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    try
    Java Code:
    Class.forName("oracle.jdbc.driver.OracleDriver");

    instead of
    Java Code:
        Class.forName("oracle.jdbc.OracleDriver");

  3. #3
    freddy000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default

    hi mine
    thank you for answering ,
    I've added "driver" in class.forname like you mentioned and it's still generating the SAME output message , no changes

  4. #4
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    Seem that the error you are getting is about drivers or/and library.

    Where did you get the library that you add?

    I am not sure with this, I have'nt try to install oracle before but just want to ask:
    Are you sure that the port 1521 is the port that you enter when you install oracle thin?

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    What version of Oracle do you have?
    What version of the driver are you using?
    What version of Java are you using?

  6. #6
    freddy000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default

    hi
    I was using oracle 8.1.7 , and I've downloaded ojdbc5.jar from the oracle official site ,

    Yes I'm sure of the port 1521 this is the default one , and i've created my table after being connected with the system account

    ok, which is really strange that I've installed oracle 10 express after, added to my library's application a jdbc that I've found in that oracle 10 directory
    now it works !!!

    so does the oracle 8.1.7 version having problem's connection ?
    thanks

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Yes.
    Oracle 8i is no longer supported, and hasn't been for a while, so I wouldn't be surprised to find that a JDBC driver designed for Oracle 10 doesn't work with it.

    If you need to use Oracle 8i then you'll want to get hold of the classes12 zip.

  8. #8
    freddy000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default

    hi Tolls
    thank you for your answer , I downloaded classes12.zip and I didn't understand what to do with the classes within :)
    I'm used to .jars files so I prefer to continue manipulating oracle 10, the connection succeeded simply :)


    thanks

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Don't unzip it.
    It is a jar file...it's just called a zip for some unknown reason.
    Use it like any other jar file.

  10. #10
    freddy000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default

    hi
    XML Code:
    Don't unzip it.
    It is a jar file...it's just called a zip for some unknown reason.
    may it was that my fault , i was expecting to find a .jar file , and it was a zip one ,
    I'll add it like it is to my library's application ,
    thanks

Similar Threads

  1. connect to oracle from java
    By ahmadian in forum Advanced Java
    Replies: 7
    Last Post: 05-15-2013, 04:15 PM
  2. Oracle Connect thru register driver
    By chyrl in forum JDBC
    Replies: 5
    Last Post: 05-11-2010, 03:45 PM
  3. new to oracle
    By emmett01 in forum JDBC
    Replies: 4
    Last Post: 11-15-2009, 06:16 AM
  4. Replies: 0
    Last Post: 08-27-2008, 09:27 AM
  5. Using JDBC to connect to ORACLE database
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-10-2008, 11:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •