9 Replies Latest reply on Dec 22, 2002 6:10 PM by 843854

    what is wrong with this!! please help

    843854
      Hello friends,

      I'm a learner and I have done lot of JDBC connectivity with Acess database, and now I want to connect java program with oracle database, but the problem is I have downloaded the oracle driver, set the classpath, and I have created the DataSource Name with MS-ODBC, I could able to compile but I'm getting run time exception, please help me with this. regards, shabeer.

      the program is

      ****************************

      import java.sql.*;

      public class ShabeerJdbc {
      public static void main(String args[]) {
      // String url = "jdbc:oracle:thin:@imran:3339:shabeerjdbc";
      Connection con;
      String createString;
      createString = "create table COFFEES " +
      "(COF_NAME VARCHAR(32), " +
      "SUP_ID INTEGER, " +
      "PRICE FLOAT, " +
      "SALES INTEGER, " +
      "TOTAL INTEGER)";
      Statement stmt;

      try {

      System.out.println("shabeer1");

      Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();

      System.out.println("shabeer2");

      } catch(java.lang.Exception e) {

      System.out.println("shabeer3");
      System.err.print("ClassNotFoundException: ");

      System.out.println("shabeer4");

      System.err.println(e.getMessage());
      }

      try {

      System.out.println("shabeer55");

      con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:shabeerjdbc", "system", "mehar");

      System.out.println("shabeer6");
      stmt = con.createStatement();

      System.out.println("shabeer7");
      stmt.executeUpdate(createString);
      stmt.close();
      con.close();

      } catch(SQLException ex) {
      System.err.println("SQLException: " + ex.getMessage());
      }
      }
      }

      *****************************

      the run time error is ......

      *****************************************

      C:\JavaPractice>java ShabeerJdbc
      shabeer1
      shabeer2
      shabeer55
      Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(Unknown Source)
      at java.security.SecureClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.defineClass(Unknown Source)
      at java.net.URLClassLoader.access$100(Unknown Source)
      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 oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
      va:468)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at ShabeerJdbc.main(ShabeerJdbc.java:38)


      ****************************************
        • 1. Re: what is wrong with this!! please help
          843854
          Can't tell you for sure, but it looks like you are using the Oracle thin driver. The Oracle thin driver does not require, nor will it use an ODBC Datasource. In the connection string, you should be supplying the SID name, not an ODBC Datasource name.

          It looks like you are supplying the ODBC Datasource name "shabeerjdbc" which is incorrect. Instead try using the SID name.

          con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:shabeerjdbc", "system", "mehar");
          • 2. Re: what is wrong with this!! please help
            843854
            HI Deriderj, thanks for your response, well I have changed the Datasourse name to SID which is "Imran" and still it is not working....do I need to download anymore driver or whether they be bundled with the ojdbc.jar, please advice me. What if I want to use another driver as you mentioned...not to use thin: what other drivers will be available for the Oracle9.2.0.1.0 please advice me, thanks a lot

            My SID name is "Imran"

            listening port is is 1521

            odbc datasource name is "shabeerjdbc"

            I'm a very biginner and I'm facing too much problem, please help me. Well I have got Oracle9.2.0.1.0 loaded as the database and soon after I intstalled it I have copied ojdbc14.jar into my java classpath and I'm trying to connect to this data base. I dont know what driver I should use, neither I downloaded any. I'm just mentioning thin: in my URL. But It is giving error, can u please tell me what driver should I mention in the URL, and why I'm getting this error, Here is the code that is compiling without errors.

            *********************************************************

            import java.sql.*;

            public class ShabeerJdbc {
            public static void main(String args[]) {
            Connection con;
            String createString;
            createString = "create table COFFEES " +
            "(COF_NAME VARCHAR(32), " +
            "SUP_ID INTEGER, " +
            "PRICE FLOAT, " +
            "SALES INTEGER, " +
            "TOTAL INTEGER)";
            Statement stmt;

            try {
                 
                 System.out.println("shabeer1");

            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                 
                 System.out.println("shabeer2");

            } catch(java.lang.Exception e) {

                 System.out.println("shabeer3");
            System.err.print("ClassNotFoundException: ");
                 
                 System.out.println("shabeer4");

            System.err.println(e.getMessage());
            }

            try {

                 System.out.println("shabeer55");

            con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:Imran", "system", "mehar");

                 System.out.println("shabeer6");
                 stmt = con.createStatement();

                 System.out.println("shabeer7");
                 stmt.executeUpdate(createString);
            stmt.close();
            con.close();

            } catch(SQLException ex) {
            System.err.println("Sql Exception" + ex.getMessage());
            }
            }
            }

            ************The runtime Error it is giving is *********************


            C:\JavaPractice>java ShabeerJdbc
            shabeer1
            shabeer2
            shabeer55
            Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
            at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
            va:468)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at ShabeerJdbc.main(ShabeerJdbc.java:38)
            ***************************** please help me....
            • 3. Re: what is wrong with this!! please help
              843854
              Check in your Oracle installed dir for ora81\jdbc\lib\classes12.zip. Include that zip file in the classpath and remove whatever you have put earlier.

              Totally forget about 'Odbc' and odbc drivers. They are no more required. You can use this thin driver to get connected to the Oracle Server.

              If you don't have classes12.zip, let me know and give your email id.

              Sudha
              • 4. Re: what is wrong with this!! please help
                843854
                Check in your Oracle installed dir for
                ora81\jdbc\lib\classes12.zip. Include that zip file in
                the classpath and remove whatever you have put earlier.
                Classes12.zip is for the older Oracle versions. When using 9.x you should use the new JDBC driver which comes as ojdbc14.jar which is downloadable from Oracle's web site.
                Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
                indicates a problem with the JDBC driver. The Savepoint class has been introduced in JDK 1.4 and the old 12 classes do not implement that. But looking at your code I'm kind of confused that this should produce the given classnot found exception. Which JDK are you using?

                Thomas
                • 5. Re: what is wrong with this!! please help
                  843854
                  Many thanks Sudha, I have done the same as per your instructions, I reckon well the problem has slightly improved, and I'm getting an exception saying that, the network adapter couldn't establish the connection. I wonder if you could tell me what exactly is SID name, I think it is the database name isn't it?? I have picked that up from listener.ora file where it is mentioned SID Description and SID name. I will be very grateful to you if you could solve this problem, it is blowing off my head. please help me.

                  Well my JDK version is JDK1.4.1_01 and Oracle version is Oracle9.2.0.1.0 and , in the C:\oracle\ora92\jdbc\lib directory there are ojdbc14.jar and classes12.zip, both are available, and I have removed the ojdbc14.jar from the classpath and added the classes12.zip file, and now the problem has improved a bit it seems,

                  please help me.....awaiting for your reply.... and my e-mail ID is

                  shabeermiah@yahoo.com


                  here is the code that is compiling

                  **********************************************************

                  import java.sql.*;

                  public class ShabeerJdbc {
                  public static void main(String args[]) {
                  Connection con;
                  String createString;
                  createString = "create table COFFEES " +
                  "(COF_NAME VARCHAR(32), " +
                  "SUP_ID INTEGER, " +
                  "PRICE FLOAT, " +
                  "SALES INTEGER, " +
                  "TOTAL INTEGER)";
                  Statement stmt;

                  try {
                       
                       System.out.println("shabeer1");

                  DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());


                       System.out.println("shabeer2");

                  } catch(java.lang.Exception e) {

                       System.out.println("shabeer3");
                  System.err.print("ClassNotFoundException: ");
                       
                       System.out.println("shabeer4");

                  System.err.println(e.getMessage());
                  }

                  try {

                       System.out.println("shabeer55");

                  con = DriverManager.getConnection("jdbc:oracle:thin:@213.122.59.72:1521:Imran", "System", "mehar");

                       System.out.println("shabeer6");
                       stmt = con.createStatement();

                       System.out.println("shabeer7");
                       stmt.executeUpdate(createString);
                  stmt.close();
                  con.close();

                  } catch(SQLException ex) {
                  System.err.println("Sql Exception" + ex.getMessage());
                  }
                  }
                  }


                  **********************************************************



                  and the runtime error is ...........

                  C:\JAVAPR~1>java ShabeerJdbc
                  shabeer1
                  shabeer2
                  shabeer55
                  Sql ExceptionIo exception: The Network Adapter could not establish the connection


                  • 6. Re: what is wrong with this!! please help
                    843854
                    Hi Thomas,

                    thanks for your message, Well I'm using jdk1.4.1_01 and oracle version is oracle oracle9.2.0.1.0, I have done the same as sudha explained me, the problem has slightly improved and now it is saying that "the network adaptor couldn't able to to establish the connection. " I'm really confused what the problem is: please help me, well i have posted the compiling code and the error, please help me and my mail ID is shabeermiah@yahoo.com

                    regards
                    shabeer.
                    • 7. Re: what is wrong with this!! please help
                      843854
                      con = DriverManager.getConnection("jdbc:oracle:thin:@213.122.59.72:1521:Imran", "System", "mehar");
                      1.Open a command prompt in your Oracle server (not your client machine) and type this,
                      sqlplus system/mehar@Imran
                      If you can get connected to oracle, then your SID is 'Imran'.

                      2.Then check your server's ip address, it should be '213.122.59.72', otherwise you can use DNS name also instead of IP.

                      3.If both are correct, then check the port on which your listener is listening to requests. You can test it via,
                      Start-->Programs-->Oracle-->Network Administration-->Net8 Configuration Assistant.

                      Sudha
                      • 8. Re: what is wrong with this!! please help
                        843854
                        Hi Sudha,

                        Many thanks for your help, well I was trying different options and I wanted to connect to Oracle database by any means, so I have tried to use oci8 driver and it did work, and this program is working fine.

                        ******************************************************

                        import java.sql.*;

                        public class ShabeerJdbc {
                        public static void main(String args[]) {
                        Connection con;
                        String createString;
                        createString = "create table COFFEES " +
                        "(COF_NAME VARCHAR(32), " +
                        "SUP_ID INTEGER, " +
                        "PRICE FLOAT, " +
                        "SALES INTEGER, " +
                        "TOTAL INTEGER)";
                        Statement stmt;

                        try {
                             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                        } catch(java.lang.Exception e) {
                        System.err.print("ClassNotFoundException: ");
                        System.err.println(e.getMessage());
                        }

                        try {
                        con = DriverManager.getConnection("jdbc:oracle:oci8:@IMRAN", "scott", "tiger");
                             stmt = con.createStatement();
                             stmt.executeUpdate(createString);
                        stmt.close();
                        con.close();

                        } catch(SQLException ex) {
                        System.err.println("Sql Exception" + ex.getMessage());
                        }
                        }
                        }
                        *************************************************

                        but the thin driver concept still the same chaos, but I'm leaving that for now, well many thanks for your kind help, your info was so much useful.
                        regards,
                        shabeer
                        • 9. Re: what is wrong with this!! please help
                          843854
                          I think you are right Thomas. Problem is probably with JDK.
                          In command line, type: java -version
                          You will probably see that you are not using JDK 1.4; it's because of JDK 1.3. installed by Oracle database. Check your PATH settings and make sure that the path to JDK 1.4./bin directory is the first.