1 Reply Latest reply: Oct 18, 2013 2:56 AM by Gellért RSS

    server side javascript: jdbc package import?

    Gellért

      I am trying to use mozilla rhino or the standard java scripting api (javax.script) to access oracle through jdbc from javascript. It seems however, that i cannot import the necessary oracle packages:

       

      importPackage(java.sql);

      importPackage(oracle.jdbc);

      importPackage(oracle.jdbc.pool.OracleDataSource);

      ....

       

      I run my sample code (code.js) with rhino as here:

       

      D:\MyDocuments\Docs\Javascript>java -classpath "D:\oracle\product\12.1.0\dbhome\jdbc\lib\ojdbc7.jar;D:\oracle\product\12.1.0\dbhome\jlib\orai18n.jar;rhino1_7R4\js.jar" org.mozilla.javascript.tools.shell.Main code.js

       

      js: uncaught JavaScript runtime exception: ReferenceError: "oracle" is not defined.

       

      The same error occurs when using the java scripting api directly.

       

      I am not really a javascript coder, i experiment for a specific reason. Any help would be greatly appreciated.

        • 1. Re: server side javascript: jdbc package import?
          Gellért

          I found out, that I don't need to import the oracle packages for making the connection. The following code works.

           

          importPackage(java.sql);

           

           

          conn = java.sql.DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:db1", "user", "password");

          stmt = conn.createStatement();

           

           

          rset = stmt.executeQuery("SELECT * FROM dual");

           

           

           

           

          while (rset.next())

          {

          print(rset.getString(1));

          }

           

           

          rset.close();

          stmt.close();

          conn.close();