Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Missing Defines Error in Simple Java Stored Procedure

434510Aug 16 2005 — edited May 3 2012
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2012
Added on Aug 16 2005
8 comments
23,247 views