Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

JSP Oracle ResultSet

  Asked By: Almas    Date: May 21    Category: Java    Views: 5000
  

I apologize if this is off topic and JSP questions should be sent
elsewhere.

I'm new to JSP (coming from an ASP background) so please forgive me.

I've got a class method that returns a ResultSet object. I
instantiate an object of the class and call the method from a stand-
alone Java application and it seems to work okay. I iterate through
the ResultSet using 'rs.getString(i)' where i is 1-3 from the three
columns returned. This subscript of '1' actually displays the first
column, which I would think would be '0' but whatever... When I take
this code and put it in my JSP, it doesn't like the subscript '3' and
actually displays the second SQL column as subscript '1'. Thought
this looked more normal so I changed the range to 0-2 and I error out
on '0' as well. Both write out something like this to my web server
error log: 'root cause: java.sql.SQLException: Invalid column index'

Any ideas? Dumb question?

--- JSP CODE ---
<%@page contentType="text/html"%>
<%@ page import="java.io.*, java.lang.*, java.sql.*, Memo_Tracker" %>
<%
String page_Title = "Memo Tracker";

Memo_Tracker myMemo = new Memo_Tracker();
ResultSet rs = myMemo.report_Memo(3,1);
%>
SOME HTML ENDING WITH BODY TAG
<%-- <jsp:useBean id="beanInstanceName" scope="session"
class="package.class" /> --%>
<%-- <jsp:getProperty name="beanInstanceName"
property="propertyName" /> --%>
MORE HTML SETTING UP A TABLE
<%
while (rs.next()) {
out.println("<tr>");
out.println(" <td>" + rs.getString(1) + "</td>");
out.println(" <td>" + rs.getString(2) + "</td>");
// out.println(" <td>" + rs.getString(3) + "</td>");
out.println("</tr>");
}
%>

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Aaminah Khan     Answered On: May 21

In my opinion,

Try putting the column  name within double qoutes, in
stead of numbers 1-3.

For example if your SQL goes like this.
select name,roll,address from table_name;

Then the the code  goes like this,

rs.getString("name");
rs.getString("roll");
rs.getString("address");

Try this.
http://techtips.ontheweb.com

 
Answer #2    Answered By: Anne Powell     Answered On: May 21

Okay, now this is strange. My SQL in the java class  returns two
columns:

String SQLString = " SELECT f.faq_id, m.read_datetime " +
" FROM ckbshipping.faqs f, " + ...

When I change the index from 0 & 1 to "faq_id" and "read_datetime" it
still breaks with an invalid column  name. However, commenting out
the "faq_id" line and leaving the "read_datetime" still works.

I'm really confused now - If anyone can help this newbie, I'd be very
appreciative.

 
Answer #3    Answered By: Tate Thompson     Answered On: May 21

are you sure your faq_id is a string?

 
Answer #4    Answered By: Charlie Evans     Answered On: May 21

My problem turned out to be iPlanet's caching of the class. If I restarted
the server or cleared the cache through iPlanet, my column  differences were
realized and it recognized the new columns in my select statement. Nothing
like many hours of troubleshooting.

 
Didn't find what you were looking for? Find more on JSP Oracle ResultSet Or get search suggestion and latest updates.




Tagged: