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
posted
0
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
posted
0
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
posted
0
No, each field is returned as a String from the ResultSet Object. The integers in the parentheses are column numbers. Kevin
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
posted
0
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
posted
0
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
posted
0
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
posted
0
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).]