Results 1 to 4 of 4
  1. #1
    jperson is offline Member
    Join Date
    Jan 2010
    Posts
    61
    Rep Power
    0

    Default problem to insert data in oracle database

    i'm using netbeans i make a connection of database successfully
    i show tables and i can edit it using sql command

    now i want to make a small program to insert data but i have a problem
    i can't solve it :confused::confused:

    Java Code:
    package database;
    
    import java.sql.*;
    public class Insert {
      public static void main(String[] args) {
    
     try {
          Connection con=null;
          Class.forName("oracle.jdbc.OracleDriver");
          con=DriverManager.getConnection("jdbc:oracle:thin:@folic-pc:1521:orcl",
            "camp",
            "camp");
          Statement s=con.createStatement();
          s.execute("insert into test values (10,'the folic')");
    
          s.close();
          con.close();
       } catch(Exception e){
           e.printStackTrace();}
    
     }
    }
    java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:320)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:169)
    at database.Insert.main(Insert.java:10)
    please i need help :(:(
    Last edited by jperson; 03-15-2010 at 01:12 AM.

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    you need to include the oracle jdbc driver .jar file in the classpath when you run the command line application.
    e.g.

    java -jar ojdbc16.jar;. database.Insert

    or what ever the jar file is called or located.

  3. #3
    jperson is offline Member
    Join Date
    Jan 2010
    Posts
    61
    Rep Power
    0

    Default

    thank you travishein for your reply

    but i'm using NetBeans IDE 6.5.1 .. how can i rum my code correctly (where i can put the driver on myroject?)

  4. #4
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    im not familiar with netbeans, i use eclipse.
    but you should be able to make a 'lib' folder inside your module or project, and then have the project build path settings include this jar file into the classpath. that would allow for the compilation and launching test classes or applications from within netbeans to find this database driver jar file and make use if.

Similar Threads

  1. how to display data from oracle database?
    By deru4jesus in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-16-2009, 08:46 AM
  2. Replies: 3
    Last Post: 02-28-2009, 09:17 AM
  3. How to insert java Object in oracle database
    By Thilkumar82 in forum Advanced Java
    Replies: 9
    Last Post: 08-13-2008, 11:33 AM
  4. Replies: 3
    Last Post: 08-05-2008, 03:19 AM
  5. Probeleme with insert into database oracle
    By bachtoutou in forum New To Java
    Replies: 0
    Last Post: 05-24-2008, 11:56 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
  •