"NullPointerException" using LS2J - works with all Java?

Hi, I am trying to access a Java Class from LotusScript and keep getting “LS2J Error: Threw java.lang.NullPointerException”.

I wrote my class in Netbeans - tested it from within an all java application and no problems.

I copied the java code into a Java Script Library in notes, added the classes12.zip to the project (jdbc driver for oracle) and successfully compiled the java script library.

Here is the java class:

import oracle.jdbc.driver.*;

import java.sql.*;

public class OracleConnection {

private Connection con;

private Statement stmt;

private ResultSet rs;

private String sql;



/** Constructor will load the driver and connect to the specified database URL using the credentials provided.*/

public OracleConnection(String url, String dbUser, String dbPassword) {

try {

// load the driver.

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

// establish the connection.

    this.con = DriverManager.getConnection(url, dbUser, dbPassword);			

// set up SQL query.

    this.stmt=con.createStatement();

    

} catch(Exception e) {

    e.printStackTrace();

}

}

public ResultSet runQuery(String qry){

try {

    this.sql=qry;	

    this.rs=this.stmt.executeQuery(this.sql);

} catch (Exception e){

    return null;

}	

return this.rs;

}



public ResultSet getResultSet(){

return this.rs;

}



public String getXmlResults(){

    int i, row=1;

    String xml = "<xml>";

    try {

        ResultSetMetaData rsMeta=this.rs.getMetaData();

        while (this.rs.next()){

            xml+="<row count=\"" + row + "\">";

            for (i=1; i<=rsMeta.getColumnCount(); i++){

                xml+="<" + rsMeta.getColumnName(i) + ">" + rs.getString(i) + "</" + rsMeta.getColumnName(i) + ">";

            }

            xml+="</row>";

            row++;

        }

    } catch (SQLException e){

        //nothing here.

    }

    xml+="</xml>";

return xml;

}

}

Here is the lotusscript that uses the class:

(options)

Option Public

Uselsx “*javacon”

Use “javaLib”

(initalise)

Sub Initialize

Set jSession = New JavaSession()

Dim url As String, dbUser As String, dbPassword As String, qry As String

Dim results As String



url="jdbc:oracle:oci8:@dbName"

dbUser="myuser"

dbPassword="mypassword"



qry="tested and valid SQL"



Dim conClass As JavaClass, resClass As JAVACLASS

Dim conObj As JavaObject 

Dim resObj As JavaObject



Set conClass=jSession.getClass("OracleConnection")

Set conObj = conClass.CreateObject("(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", _

url, dbUser, dbPassword)

’ Set resClass=jSession.getClass(“java/sql/ResultSet”)

’ Set resObj=resClass.CreateObject()

Set resObj = conObj.runQuery(qry)

’ results=conObj.getXmlResults()

Print "finished now"

End Sub

The problem seems to be in the runQuery method. I’ve tried a few things. Returning void and using getResults/getXmlResults and so on, but it always seems to fall over (probably) on this.stmt.executeQuery(…)

As usual, any suggestions greatly appreciated. I’m not even really sure how to go about debugging this as I’m only getting started on the java stuff.

I’m contemplating scrapping the LS agent and doing the whole thing in java…