Missing Defines Error in Simple Java Stored Procedure

Advertisement
Anyone have any suggestions on what might be causing the unusual behavior described below? Could it be a 10g java configuration issue? I am really stuck so I'm open to just about anything. Thanks in advance.
I am writing a java stored procedure and am getting some SQLException's when executing some basic JDBC code from within the database. I reproduced the problem by writing a very simple java stored procedure which I have included below. The code executes just fine when executed outside of the database (10g). Here is the output from that execution:
java.class.path=C:\Program Files\jEdit42\jedit.jar
java.class.version=48.0
java.home=C:\j2sdk1.4.2_04\jre
java.vendor=Sun Microsystems Inc.
java.version=1.4.2_04
os.arch=x86
os.name=Windows XP
os.version=5.1
In getConnection
Executing outside of the DB
Driver Name = Oracle JDBC driver
Driver Version = 10.1.0.2.0
column count=1
column name=TEST
column type=1
TEST
When I execute it on the database by calling the stored procedure I get:
java.class.path=
java.class.version=46.0
java.home=/space/oracle/javavm/
java.vendor=Oracle Corporation
java.version=1.4.1
os.arch=sparc
os.name=Solaris
os.version=5.8
In getConnection
We are executing inside the database
Driver Name = Oracle JDBC driver
Driver Version = 10.1.0.2.0
column count=1
column name='TEST'
column type=1
MEssage: Missing defines
Error Code: 17021
SQL State: null
java.sql.SQLException: Missing defines
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:158)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.OracleResultSetImpl.getString(Native Method)
at OracleJSPTest.test(OracleJSPTest:70)
Here is the Java code:
// JDBC classes
import java.sql.*;
import java.util.*;
//Oracle Extensions to JDBC
import oracle.jdbc.*;
import oracle.jdbc.driver.OracleDriver;
public class OracleJSPTest {
private static void printProperties(){
     System.out.println("java.class.path="+System.getProperty("java.class.path"));
     System.out.println("java.class.version="+System.getProperty("java.class.version"));
     System.out.println("java.home="+System.getProperty("java.home"));
     System.out.println("java.vendor="+System.getProperty("java.vendor"));
     System.out.println("java.version="+System.getProperty("java.version"));
     System.out.println("os.arch="+System.getProperty("os.arch"));
     System.out.println("os.name="+System.getProperty("os.name"));
     System.out.println("os.version="+System.getProperty("os.version"));
private static Connection getConnection() throws SQLException {
     System.out.println("In getConnection");      
Connection connection = null;
// Get a Default Database Connection using Server Side JDBC Driver.
// Note : This class will be loaded on the Database Server and hence use a
// Server Side JDBC Driver to get default Connection to Database
if(System.getProperty("oracle.jserver.version") != null){
          System.out.println("We are executing inside the database");
          //connection = DriverManager.getConnection("jdbc:default:connection:");                    
          connection = new OracleDriver().defaultConnection();
}else{
     System.out.println("Executing outside of the DB");
     DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
     connection = DriverManager.getConnection("jdbc:oracle:thin:@XXX.XXX.XXX.XX:XXXX:XXXX","username","password");
DatabaseMetaData dbmeta = connection.getMetaData();
System.out.println("Driver Name = "+ dbmeta.getDriverName());
System.out.println("Driver Version = "+ dbmeta.getDriverVersion());
return connection;
public static void main(String args[]){     
     test();     
public static void test() {   
     printProperties();
Connection connection = null; // Database connection object
try {
     connection = getConnection();
     String sql = "select 'TEST' from dual";
     Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);     
     ResultSetMetaData meta = rs.getMetaData();     
     System.out.println("column count="+meta.getColumnCount());
     System.out.println("column name="+meta.getColumnName(1));
     System.out.println("column type="+meta.getColumnType(1));
     if(rs.next()){
          System.out.println(rs.getString(1));
} catch (SQLException ex) { // Trap SQL Errors
     System.out.println("MEssage: " + ex.getMessage());
     System.out.println("Error Code: " + ex.getErrorCode());
     System.out.println("SQL State: " + ex.getSQLState());
     ex.printStackTrace();
} finally {
try{
if (connection != null || !connection.isClosed())
connection.close(); // Close the database connection
} catch(SQLException ex){
ex.printStackTrace();
Message was edited by:
jason_mac
Advertisement

Replay

Jason,
Works for me on Oracle 10.1.0.3 running on Red Hat Enterprise Linux AS release 3 (Taroon).
Java code:
import java.sql.*;
* Oracle Java Virtual Machine (OJVM) test class.
public class OjvmTest {
  public static void test() throws SQLException {
    Connection conn = DriverManager.getConnection("jdbc:default:connection:");
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
      ps = conn.prepareStatement("select 'TEST' from SYS.DUAL");
      rs = ps.executeQuery();
      if (rs.next()) {
        System.out.println(rs.getString(1));
    finally {
      if (rs != null) {
        try {
          rs.close();
        catch (SQLException sqlEx) {
          System.err.println("Error ignored. Failed to close result set.");
      if (ps != null) {
        try {
          ps.close();
        catch (SQLException sqlEx) {
          System.err.println("Error ignored. Failed to close statement.");
}And my PL/SQL wrapper:
create or replace procedure P_J_TEST as language java
name 'OjvmTest.test()';And here is how I execute it in a SQL*Plus session:
set serveroutput on
exec dbms_java.set_output(2000)
exec p_j_testGood Luck,
Avi.