This discussion is archived
7 Replies Latest reply: Sep 17, 2012 9:48 AM by rp0428 RSS

jdbc

962021 Newbie
Currently Being Moderated
i am new to java .......
i am facing a problem of "no suitable driver found " in java database connectivity using type 4 drivers although i have set the class path of jar file.
so please give me some hint to solve this problem.
  • 1. Re: jdbc
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!
    >
    i am facing a problem of "no suitable driver found " in java database connectivity using type 4 drivers although i have set the class path of jar file.
    so please give me some hint to solve this problem.
    >
    You should mark this question ANSWERED and repost the question in the JDBC forum.
    https://forums.oracle.com/forums/category.jspa?categoryID=288

    When you repost provide the java code, the class path you are using and the jar file name.

    That problem can be caused by a syntax error when specifying the url; there is not driver that understands the url specified.

    See Chap 8 Data Sources and URLs in the JDBC Developer's Guide for how to specify urls.
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/urls.htm#BEIDBFDF
    String url = "jdbc:oracle:thin:@//myHost:1521/service_name";
  • 2. Re: jdbc
    rukbat Guru Moderator
    Currently Being Moderated
    Moderator Action:
    Post moved from the New To Java forum,
    to the JDBC forum,
    for closer topic alignment.
  • 3. Re: jdbc
    962021 Newbie
    Currently Being Moderated
    my source code is-

    import java.lang.*;
    import java.sql.*;
    class Testdb4o {
    public static void main(String a[]) {
    try{
    try{
    Class.forName("oracle.jdbc.driver.oracleDriver");
    }
    catch(ClassNotFoundException c){System.out.println(c);}
    Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","oracle");
    Statement s=c.createStatement();
    ResultSet rs1=s.executeQuery("select * from Students");
    while(rs1.next()){
    System.out.println(rs1.getString(1));
    System.out.println(rs1.getString(2));
    }
    //c.close();
    }
    catch(SQLException e){System.out.println(e);}
    catch(Exception i){System.out.println(i);}
    }
    }


    and i havae set the classpath of the driver as-------"C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;"

    please suggest me some solution to this problem.
  • 4. Re: jdbc
    rp0428 Guru
    Currently Being Moderated
    >
    please suggest me some solution to this problem.
    >
    Thanks for posting the code and classpath. Now we can see what the problem is.

    This code
    Class.forName("oracle.jdbc.driver.oracleDriver");
    is using the wrong class name. The name of the class is 'OracleDriver' with an uppercase 'O'.

    Use
    Class.forName("oracle.jdbc.driver.OracleDriver");
    That ojdbc14.jar is an ancient jar file. You should upgrade to the current jar version.
  • 5. Re: jdbc
    962021 Newbie
    Currently Being Moderated
    thank you sir, now every thing is working well.........
  • 6. Re: jdbc
    dsurber Explorer
    Currently Being Moderated
    If you are using JDK 1.6 or later, there is no need for Class.forName at all. It's a slow method and a waste of time. See http://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html.

    If you are using an ancient, desupported, pre-1.6 driver, then the correct class name is "oracle.jdbc.OracleDriver". No "...driver..." . oracle.jdbc.driver.OracleDriver has been desupported since 11.1.
  • 7. Re: jdbc
    rp0428 Guru
    Currently Being Moderated
    OP is the one with the quesion/issue. If you have information that you think will assist them you should direct your response to them.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points