Hi All,
I have been trying my hand on stored procedures in derby(JavaDB 10.8) with an example for 2 days now.
I need to fetch some records from a table 'tbl_students' using it.
But i keep getting a NulPointerException, I cant figure out why.
This procedure takes mainly 2 parameters – pagenumber & maxRows, both as integers.
I created the stored procedure in derby using this:
I created the class and the method, compiled it and even packed it into a jar file properly without any error.
StudentStoredProcs.java
I created the database,table and even populated it data.
I installed the jar file(pagsortex.jar) without any error using this:
The class i wrote to call this stored procedure :
StudentStoredProcTest.java
The error trace i got is:
java sptest.StudentStoredProcTest
Connection established successfully!
SQL Error:The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
java.sql.SQLException: The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.seeNextException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedCallableStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeQuery(Unknown Source)
at sptest.StudentStoredProcTest.testIt(StudentStoredProcTest.java:22)
at sptest.StudentStoredProcTest.main(StudentStoredProcTest.java:58)
Caused by: java.sql.SQLException: The exception 'java.lang.NullPointerException' was thrown while evaluating an expression.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 13 more
Caused by: java.sql.SQLException: Java exception: ': java.lang.NullPointerException'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
... 10 more
Caused by: java.lang.NullPointerException
at derby.pagesortex.StudentStoredProcs.pageStudents(StudentStoredProcs.java:32)
at org.apache.derby.exe.acf81e0010x0142xc795x43dex00000167f4380.g0(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.derby.impl.services.reflect.ReflectMethod.invoke(Unknown Source)
at org.apache.derby.impl.sql.execute.CallStatementResultSet.open(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.executeStmt(Unknown Source)
at org.apache.derby.impl.sql.GenericPreparedStatement.execute(Unknown Source)
... 6 more
Although I did this referring
DerbySQLroutine-DB-derby-wiki, this code is mine for most of the part.
So, i know errors are bound to exist
Any input is greatly appreciated.
Sree
PS:I believe this logic may too have mistakes, do point out if that strikes you...