• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

scriptlet method to return resultSet help

 
Jeff Rozycki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do I pass a resultSet back to a scriptlet?
I can not use Javabeans either since we are running (at work) iplanet 4.1 (no web-inf) and I do not have permissions to the class path. All my logic must be performed in jsp files....
===
Here is my attempt:
<%
ResultSet rs = getResultSet("SELECT * FROM COFFEES");
//Loop through results of query.
while(rs.next())
{
out.println( rs.getString("Coffee_Name"));
}
%>

<%!
public ResultSet getResultSet(String strQuery) {
ResultSet theResultSet;
theResultSet = null;
try
{
Class.forName(OracleDriver);
conn = DriverManager.getConnection(OracleAddress, OracleLogin, OraclePasswd);
Statement stmt = conn.createStatement();
theResultSet = stmt.executeQuery("SELECT * FROM COFFEES");
}
// *********************** Catch and Finals *****************
catch(SQLException e){System.out.println( "<B>Error Connecting to Oracle");System.out.println( "</B>");}
catch(ClassNotFoundException e) {System.out.println("ClassNotFoundException: " + e.getMessage() + "<BR>");}
finally {if(conn != null){try{conn.close();}catch (Exception ignored) {}}}
// **************************************************
return theResultSet;
}
%>

Problem is I keep getting:
Internal error: exception thrown from the servlet service function <snip>
, root cause: java.lang.NullPointerException

Thanks a bunch!
Jeff
 
Jeff Rozycki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
got it!
The code I submitted worked. I had an error else where in my jsp page. Duh!
But...Now the question is is this an acceptable design approach. Again, I can not utilize beans, but I am trying to separate my java from the presentation. Rather than have duplicate code in every jsp that connects to the oracle DB, I can do a page include to attach my returnrecordset method. Does anyone see a problem/conflict with this approach.
Thanks again!
Jeff
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should use JSTL's SQL-access tags?
 
Jeff Rozycki
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish I could but our company is using iplanet 4.1. No Web-Inf. I've tried for months to get javabeans to work. I do not have access a folder in the class path. Creating a web-inf folder in my personal webspace given to me by the IT department does not work for beans, so I'm assuming I will not be able to add my own tags. Any thoughts?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic