File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes JSP Syntax Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "JSP Syntax Problem" Watch "JSP Syntax Problem" New topic
Author

JSP Syntax Problem

Kevin Wright
Ranch Hand

Joined: Jul 10, 2001
Posts: 38
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

Joined: Jul 10, 2001
Posts: 38
Sorry, I forgot the most important part: It's giving me this error that I have an "invalid type expression"
Kevin
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
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

Joined: Jul 10, 2001
Posts: 38
No, each field is returned as a String from the ResultSet Object. The integers in the parentheses are column numbers.
Kevin
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

From the look of it you need

instead of

Dave.
Kevin Wright
Ranch Hand

Joined: Jul 10, 2001
Posts: 38
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
fordsm
Greenhorn

Joined: May 22, 2001
Posts: 2
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

Joined: Jul 10, 2001
Posts: 38
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

Joined: Jul 11, 2001
Posts: 254
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.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
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).]


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JSP Syntax Problem
 
Similar Threads
ResultSet problem
How to retrive data two times from database in sinble jsp page.
Why can I display one statement only?!
JSP returning old data, database was changed correctly!
Multiple forms in a single JSP page