• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP Syntax Problem

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to put in my jsp document ( I just want to show off some capabilities of JSP, not necessarily the use of Beans or Servlets, which I think would be better ) a looping construct to make a table of info based on a query...maybe the code will help more:
/******************Begin*Code*********************/
String proj=("<--SOMETHING IS WRONG-->");//a string to be return'd
try
{
/*************************************************BLOCK*OF*REAL*DB*WORK****************/

Class.forName(DRIVER); //-->generic DB-opening routine; constants come from EWOInfo.java
Connection con = DriverManager.getConnection(URL,USER,PASSWORD);
Statement st = con.createStatement();

String query = "SELECT projectCode, dateReceived, faceValue, approvedValue, status FROM tblEWOLog WHERE" +
"faceValue > " + faceValue;

ResultSet rs = st.executeQuery(query);
while(rs.next())
{%>
<TR>
<TD><% (rs.getString(1))%></td>
<td><% (rs.getString(2))%></td>
<td><% (rs.getString(3))%></td>
<td><% (rs.getString(4))%></td>
<td><% (rs.getString(5))%></td>
</tr>
<%
}
/***********************************************************************************/
st.close();//close the streams so no problems occur.
con.close();//See ^^^^ above, okay?
}//end of try statement
catch(SQLException sqle)
{
System.out.println("SQL Exception exists in JspGenerator Method.");
}
%>
</table>
/*************************/endcode/**********************/
Thanks,
Kevin
 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I forgot the most important part: It's giving me this error that I have an "invalid type expression"
Kevin
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are those fields all varchar2. If not you may have to change it from getstring to getlong depending upon the datatype.
Beksy
 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, each field is returned as a String from the ResultSet Object. The integers in the parentheses are column numbers.
Kevin
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the look of it you need

instead of

Dave.
 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That stops the problem with the "type expression". Now I get a SQL Exception, with an error code of "0" and a SQLState of "NULL". What could be causing this?
Thanks,
Kevin
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kevin Wright:
That stops the problem with the "type expression". Now I get a SQL Exception, with an error code of "0" and a SQLState of "NULL". What could be causing this?
Thanks,
Kevin


when you catch the SQLException do an sqle.printStackTrace();
That should give you a better idea what/where the error is
 
Kevin Wright
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to log the errors? The logs in my Tomcat log folder don't have anything about the error going out, and the errors go by too fast to mean anything to me.
Kevin
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It writes on the console. My system administrator redirects all the logs to a file so that I can access it ..something like server.log. Try it.
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin,
The problem could be your where clause. What type is the database field faceValue. What type is the variable faceValue?
As far a logging for testing only, you can write the excption messages out right to the JSP page.

Tomcat will log your errors to a log. You have to change a couple of the log configurations in the server.xml file. The comments in the file will help direct you to these.
BTW one of the best tools for debug SQL errors is to print out or log the query. A simple
out.println(query);
out.println("<P>");
Can give you a lot of valuble information!
------------------
Hope This Helps
Carl Trusiak, SCJP2

[This message has been edited by Carl Trusiak (edited July 17, 2001).]
 
That new kid is a freak. Show him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic