The moose likes JSP and the fly likes scriptlet method to return resultSet help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "scriptlet method to return resultSet help" Watch "scriptlet method to return resultSet help" New topic

scriptlet method to return resultSet help

Jeff Rozycki

Joined: Jul 15, 2003
Posts: 4
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.
out.println( rs.getString("Coffee_Name"));

public ResultSet getResultSet(String strQuery) {
ResultSet theResultSet;
theResultSet = null;
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 Rozycki

Joined: Jul 15, 2003
Posts: 4
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!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Maybe you should use JSTL's SQL-access tags?

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Jeff Rozycki

Joined: Jul 15, 2003
Posts: 4
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?
I agree. Here's the link: http://aspose.com/file-tools
subject: scriptlet method to return resultSet help
Similar Threads
JDBC Connection (or "I Am At My Wits End")
newbie problem
Accessing Connection pool
A challenge while formatting date value from the database
Database Connection