Forum Moderators: coopster & phranque

Message Too Old, No Replies

JSP code oddity

form elements and value attribute

         

txbakers

1:58 pm on Jul 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm hoping this can be solved and this is the right board. We don't have a specific JSP board, but someone might know it.

In at nutshell:
this works and prints on the page:
<%=rsTrusts.getObject("ALPHA")%> <%=rsTrusts.getObject("ACCT")%> <br>

this causes a "no data found" exception:
<input type="checkbox" name="check" value="<%=rsTrusts.getObject("ACCT")%> ">

It's the same code. Why does it fail inside the value expression?

I've also tried this:
<input type="checkbox" name="check" value="<%=rsTrusts.getObject("ACCT").toString()%> "> and that doesn't work either.

Any guesses?

ppg

7:50 pm on Jul 24, 2002 (gmt 0)

10+ Year Member



odd, all those three versions should give the same result.

You're getting an SQL exception - could you post some more of the code? What JDBC driver are you using?

if you havn't tried it yet, I'd try storing the value in a String variable and then seeing if you can use it the same way, like:

<%
String checkBoxValue = (String)rsTrusts.getObject("ACCT");
%>

<%=checkBoxValue%><br>
<input type="checkbox" name="check" value="<%=checkBoxValue%>">

txbakers

1:17 am on Jul 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I figured out the problem. It was a java oddity.

My SQL was "select acct, alpha from ledger"

I tried my code above just in the checkbox, without the two fields as text, and that worked.

It seems that in Java, you can't reference the object more than once. It wouldn't have mattered if I had this:

<%=rsTrusts.getObject("ALPHA")%> <%=rsTrusts.getObject("ACCT")%><%=rsTrusts.getObject("ALPHA")%>

without checkboxes, because of the double reference to alpha.

The solution:

I changed the SQL to this: "Select acct, acct as acct2, alpha from ledger"

Then wrote my JSP code as follows:
<input type="checkbox" value="<%=rsTrusts.getObject("acct2")%>">
<%=rsTrusts.getObject("ALPHA")%> <%=rsTrusts.getObject("ACCT")%>

And that worked.

Bizarre.

ppg

8:53 am on Jul 25, 2002 (gmt 0)

10+ Year Member



That is strange.

I've tried to replicate your problem, but can't - I've a feeling it may be behaviour specific to your database driver (I'm using the mm.mysql driver and can reference and re-reference objects in a ResultSet row ad infinitum).

this confuses me though:

It wouldn't have mattered if I had this:

<%=rsTrusts.getObject("ALPHA")%> <%=rsTrusts.getObject("ACCT")%><%=rsTrusts.getObject("ALPHA")%>

without checkboxes, because of the double reference to alpha.

If the problem is being able to reference the object more than once, I would expect you to get the same error here. It makes me think I may have misunderstod you?

txbakers

1:00 pm on Jul 25, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would have gotten the same error had I duplicated one of the fields as text.

I'm using a JDBC:ODBC driver to connect to an AS/400.

ppg

11:43 am on Jul 26, 2002 (gmt 0)

10+ Year Member



ah, I see.

I did a bit of digging around - it is caused by the JDBC:ODBC driver, not the JDBC API. It might be worth seeing if you can find a driver specific to the db anyway if you can, JDBC:ODBC drivers are slower than type 3 or 4 drivers.