Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: JDBC connection error

  1. #1
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JDBC connection error

    Hi iam recieving error for my code for JDBC please help me
    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 jdbcstatements.JDBCConnection.main(JDBCConnection. java:17)
    my code

    package jdbcstatements;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;



    public class JDBCConnection {

    public static void main(String[]args)
    {

    try {

    Class.forName("oracle.jdbc.driver.OracleDriver").n ewInstance();
    String url="jdbcracle:thin:@localhost:1521rcl";

    Connection con=DriverManager.getConnection( url, "scott", "tiger");
    System.out.println("connection created");

    Statement db_statement = con.createStatement();
    db_statement.executeUpdate
    ("create table employee { int id, char(50) name };");
    con.commit();
    ResultSet result = db_statement.executeQuery
    ("select * from employee");
    while (result.next() )
    {
    // Use the getInt method to obtain emp. id
    System.out.println ("ID : " + result.getInt("ID"));

    // Use the getString method to obtain emp. name
    System.out.println ("Name : " + result.getString("Name"));
    System.out.println ();
    }

    } catch(Exception e){e.printStackTrace();}

    }
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: JDBC connection error

    Quote Originally Posted by nrao View Post
    Hi iam recieving error for my code for JDBC please help me
     

    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 jdbcstatements.JDBCConnection.main(JDBCConnection. java:17)




    my code

    package jdbcstatements;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
     
     
     
    public class JDBCConnection  {
     
        public static void main(String[]args)
      {
     
        try {
     
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
          String url="jdbc:oracle:thin:@localhost:1521:orcl";
     
        Connection  con=DriverManager.getConnection(   url,   "scott", "tiger");
          System.out.println("connection created");
     
          Statement db_statement = con.createStatement();
          db_statement.executeUpdate 
          ("create table employee { int id, char(50) name };");
          con.commit();
          ResultSet result = db_statement.executeQuery
      	("select * from employee");
          while (result.next() )
          {
          	// Use the getInt method to obtain emp. id
          	System.out.println ("ID : " + result.getInt("ID"));
     
          	// Use the getString method to obtain emp. name
          	System.out.println ("Name : " + result.getString("Name"));
          	System.out.println ();
          }
     
       } catch(Exception e){e.printStackTrace();}
     
    }
    }
    Thrown when an application tries to load in a class through its string name using:

    * The forName method in class Class.
    * The findSystemClass method in class ClassLoader .
    * The loadClass method in class ClassLoader.

    but no definition for the class with the specified name could be found.

  3. #3
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC connection error

    i didnt get you what exactly is the problem please help me

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: JDBC connection error

    I must admit that I don't know much about networking, but it appears, from looking up the Class forName(String exp) method, that your forName(exp) cannot find that class.

    Maybe you have a typo there.

    Class (Java 2 Platform SE 5.0)

    Also, maybe you haven't initialized it.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: JDBC connection error

    This is a very common problem to JDBC newcomers. You must 1) download the driver (a .jar file you can get specific for your database) and 2) place the driver on your classpath.

  6. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (November 10th, 2010)

  7. #6
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC connection error

    thank you copeg .I have downloaded jar and connection has been created but the Statement is not working
    please help me.Iam getting this error
    connection created
    java.sql.SQLException: Non supported SQL92 token at position: 27: int
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:146)
    at oracle.jdbc.driver.OracleSql.handleToken(OracleSql .java:1165)
    at oracle.jdbc.driver.OracleSql.handleODBC(OracleSql. java:1064)
    at oracle.jdbc.driver.OracleSql.parse(OracleSql.java: 984)
    at oracle.jdbc.driver.OracleSql.getSql(OracleSql.java :312)
    at oracle.jdbc.driver.OracleSql.getSqlBytes(OracleSql .java:557)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStateme nt.java:193)
    at oracle.jdbc.driver.T4CStatement.executeForRows(T4C Statement.java:946)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTi meout(OracleStatement.java:1168)
    at oracle.jdbc.driver.OracleStatement.executeUpdateIn ternal(OracleStatement.java:1614)
    at oracle.jdbc.driver.OracleStatement.executeUpdate(O racleStatement.java:1579)
    at jdbcstatements.JDBCConnection.main(JDBCConnection. java:24)

  8. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,297
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: JDBC connection error

    This is an SQL error and not a java error.
    db_statement.executeUpdate("create table employee { int id, char(50) name };");

    The syntax is wrong. See the syntax for creating tables in SQL: SQL Create Table Statement. Notably, the brackets vs parenthesis.

  9. The Following User Says Thank You to copeg For This Useful Post:

    javapenguin (November 10th, 2010)

  10. #8
    Member
    Join Date
    Nov 2010
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JDBC connection error

    Thank you copeg its working

Similar Threads

  1. jdbc connection problem
    By sny in forum JDBC & Databases
    Replies: 11
    Last Post: January 6th, 2011, 03:39 AM
  2. multiple tcp connection?
    By nasser in forum Java Networking
    Replies: 4
    Last Post: July 31st, 2010, 07:35 AM
  3. jdbc connection with phpmyadmin
    By anand_fevi in forum JDBC & Databases
    Replies: 1
    Last Post: May 13th, 2010, 02:26 AM
  4. Connecting to Cache through JDBC - error
    By javavick in forum JDBC & Databases
    Replies: 0
    Last Post: May 6th, 2010, 06:34 AM
  5. cant get rid of http connection
    By kartik in forum Java Networking
    Replies: 1
    Last Post: July 21st, 2009, 03:09 AM