Your brackets were off plus you had one to many closing brackets.
This code compiles but you may need to rearrange the brackets. Just don't add any more
of them :-)
///////////////////////////////////////////////////////
<HTML><HEAD><TITLE>Report</TITLE></HEAD><BODY>
<%@ page language="java" import="java.io.*" import="java.sql.*" import="java.util.*"
import="java.text.DateFormat" import="java.text.ParseException"%>
<%!
Connection connection;
Statement statement ;
Statement statement2 ;
ResultSet rs ;
ResultSet rs2 ;
ResultSetMetaData rsmd;
static DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
static { df.setLenient (false); }
public static final int val_EXPIRED = -1;
public static final int val_CURRENT = 0;
public static final int val_FUTURE = 1;
%>
<%
Class.forName("oracle.jdbc.driver.OracleDriver" );
connection = DriverManager.getConnection( "jdbc:oracle:thin:@server:port:db", "usr",
"pword" );
statement = connection.createStatement() ;
rs = statement.executeQuery("SQL" ) ;
rsmd = rs.getMetaData();
while( rs.next() ) {
String val = rs.getString( "SQLval" ) ;
String val = rs.getString( "SQLval" ) ;
%>
<Table border="2">
<TR>
<TD>dispVal</TD><TD> <% String.valueOf(val) ; %> </TD>
</TR>
<TR>
<TD>dispVal</TD><TD> <% String.valueOf(val) ; %> </TD>
</TR>
</Table>
<BR><BR><B>Report<B><BR>
<Table border="2">
<TR>
<TH>dispVal</TH>
</TR>
<%
//count
double val = 0;
//used to hold each val found
Hashtable hash = new Hashtable ();
//obtain vals
String sql_str = "SQL";
rs2 = statement2.executeQuery(sql_str);
if (rs2 == null)
{ %> <TR><TD colspan="7">*** No vals ***"</TD></TR> <% }
else
{try
{while (rs2.next())
{ //extract the vals
String val = rs2.getString ("SQLval");
if (val == valproc)
{ //calculate the val...need to promote stop to a double, or
it will do integer division
int val = rs2.getInt ("SQLval");
int val = rs2.getInt ("SQLval");
double val = ((double) val - val)/4;
val += val;
}
//create our new hash key.
//hash key consists of:
// val.val.val.val.val
String hashKey = buf.toString() + "%" + val + "%" + val + "%" + val +
"%" + val;
//check if the hashtable has an entry for this val
if (hash.containsKey(hashKey))
{ //there is an entry...this means both the val and the val
match
//extract the line item object to update its info
PLineItem pli = (PLineItem) hash.get(hashKey);
//add the number of val to the existing entry
pli.hours += val;
hash.put (hashKey, pli);
}
else
{ //no rates match, so create a new entry
hash.put (hashKey, new PLineItem (val, val));
}
} //while
//}
//mark result set for garbage collection
rs2.close();
stmt.close();
rs2 = null;
//build the HTML rows for each item in the hashtable
for (Enumeration e = hash.keys() ; e.hasMoreElements() ; )
{String hashKey = (String) e.nextElement();
PLineItem pli = (PLineItem) hash.get(hashKey);
%> <TR> <%
StringTokenizer tokenizer = new StringTokenizer (hashKey, "%");
String val = tokenizer.nextToken ();
String val = tokenizer.nextToken ();
String val = tokenizer.nextToken ();
String val = tokenizer.nextToken ();
String val = tokenizer.nextToken ();
%>
<TD> <%= val %> </TD>
<TD> <%= val %> </TD>
<TD> <%= val %> </TD>
<TD> <%= val %> </TD>
<TD> <%= val %> </TD> </TR>
<%
} //for
} //try
//} //this is the one.. I get the no catch here, and the no try on the catch below
catch (SQLException sql_e)
{ %> </TABLE <BR><BR> <H3>An error has occurred accessing the database. Unable to
retrieve vals.</H3><BR><BR>
<% }
}
//add val to the table
%>
<TR>
<TD Colspan="2">val</TD><TD> <%= val %> </TD>
</TR>
</TABLE>
<BR><BR>
<%
}
%>
<%!
/**
Convenience function for determining if a val is current, expired or future.
@param sDate: start date formatted in the Oracle 'DD-MON-YYYY' format (may be
null).
@param eDate: end date formatted in the Oracle 'DD-MON-YYYY' format (may be
null).
@return val_EXPIRED if the val is expired.
val_CURRENT if the val is current.
val_FUTURE if the val is future.
*/
public static int valproc (String sDate, String eDate)
{
//get our current date
java.util.Date today = new java.util.Date ();
//determine if this is a current val (and not a future val or expired val)
//build the dates for this entry using our date format
java.util.Date startDate = null;
try
{
startDate = df.parse (sDate);
}
catch (ParseException p_e)
{ /*ignored...startDate will simply remain null, which is fine */ }
java.util.Date endDate = null;
try
{
endDate = df.parse (eDate);
}
catch (ParseException p_e)
{ /*ignored...endDate will simply remain null, which is fine */ }
//if the enddate is not null, compare it to the current date. If it is
less than the
//current date, this is an expired val.
if ((endDate != null) && (endDate.before (today)))
{
return val_EXPIRED;
}
//if the startdate is not null, compare it to the current date. If it is more
than the
//current date, this is a future val.
if ((startDate != null) && (startDate.after (today)))
{
return val_FUTURE;
}
//all other cases are current val.
return val_CURRENT;
}
%>
</BODY>
</HTML>
LeBaron Price wrote:
> Good Morning Neighbors;
>
> I've been beating my head against this wall for a couple days now, and feel as
>though I have exhausted all my other available resources (even the guys in my own
>shop won't talk to me anymore.) I've got some code that appears to be structured fine
>(I'll include the skeleton at the bottom of the message.) unfortunately any time I
>try to run it I get two errors..
>
> 'try' without 'catch' or 'finally'. }
> 'catch' without 'try'. catch (SQLException sql_e)
>
> They're back to back, why for the love of the goddess can't they find each other?
>I'm using emacs and when I delete the end bracket just above the catch statement and
>put another in it's place, it tells me it matches the beginning of the try statement.
> I thought maybe it was some hidden character that I wasn't seeing that was messing
>me up, but I just finished retyping the catch block by hand and didn't have any
>success.
>
> Has any one out there run into a similar issue with java in the past? I could really
>use the help, I need this code up, and I'm about ready to throw out the exception
>handling all together (the programmer gods gasp at my blasphemy * I repent I repent)
>
> Any how, if you can forgive my neurotic bitterness and offer any advice it would be
>greatly appreciated,
> Thanks in advance,
>
> Peace,
> LeBaron.
>
> Code follows (I apologize in advance for the horrible formatting on this, it's been
>copied from unix to windows and from word to notepad, I tried to clean it up a bit,
>but I had to make some compromise for readability in a text wrapping environment. )
>
> <HTML><HEAD><TITLE>Report</TITLE></HEAD><BODY>
>
> <%@ page language="java" import="java.io.*" import="java.sql.*" import="java.util.*"
>import="java.text.DateFormat" import="java.text.ParseException"%>
>
> <%!
> Connection connection;
> Statement statement ;
> Statement statement2 ;
> ResultSet rs ;
> ResultSet rs2 ;
> ResultSetMetaData rsmd;
> static DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
> static { df.setLenient (false); }
> public static final int val_EXPIRED = -1;
> public static final int val_CURRENT = 0;
> public static final int val_FUTURE = 1;
> %>
>
> <%
> Class.forName("oracle.jdbc.driver.OracleDriver" );
> connection = DriverManager.getConnection( "jdbc:oracle:thin:@server:port:db", "usr",
>"pword" );
> statement = connection.createStatement() ;
>
> rs = statement.executeQuery("SQL" ) ;
> rsmd = rs.getMetaData();
>
> while( rs.next() ) {
> String val = rs.getString( "SQLval" ) ;
> String val = rs.getString( "SQLval" ) ;
> %>
>
> <Table border="2">
> <TR>
> <TD>dispVal</TD><TD> <% String.valueOf(val) ; %> </TD>
> </TR>
> <TR>
> <TD>dispVal</TD><TD> <% String.valueOf(val) ; %> </TD>
> </TR>
> </Table>
>
> <BR><BR><B>Report<B><BR>
>
> <Table border="2">
> <TR>
> <TH>dispVal</TH>
> </TR>
> <%
> //count
> double val = 0;
> //used to hold each val found
> Hashtable hash = new Hashtable ();
> //obtain vals
> String sql_str = "SQL";
> rs2 = statement2.executeQuery(sql_str);
> if (rs2 == null)
> { %> <TR><TD colspan="7">*** No vals ***"</TD></TR> <% }
> else
> {try
> {while (rs2.next())
> { //extract the vals
> String val = rs2.getString ("SQLval");
> if (val == valproc)
> { //calculate the val...need to promote stop to a double,
>or it will do integer division
> int val = rs2.getInt ("SQLval");
> int val = rs2.getInt ("SQLval");
> double val = ((double) val - val)/4;
> val += val;
> }
> //create our new hash key.
> //hash key consists of:
> // val.val.val.val.val
> String hashKey = buf.toString() + "%" + val + "%" + val + "%" + val
>+ "%" + val;
> //check if the hashtable has an entry for this val
> if (hash.containsKey(hashKey))
> { //there is an entry...this means both the val and the
>val match
> //extract the line item object to update its info
> PLineItem pli = (PLineItem) hash.get(hashKey);
> //add the number of val to the existing entry
> pli.hours += val;
> hash.put (hashKey, pli);
> }
> else
> { //no rates match, so create a new entry
> hash.put (hashKey, new PLineItem (val, val));
> }
> }
> }
> //mark result set for garbage collection
> rs2.close();
> stmt.close();
> rs2 = null;
>
> //build the HTML rows for each item in the hashtable
> for (Enumeration e = hash.keys() ; e.hasMoreElements() ; )
> {String hashKey = (String) e.nextElement();
> PLineItem pli = (PLineItem) hash.get(hashKey);
> %> <TR> <%
> StringTokenizer tokenizer = new StringTokenizer (hashKey, "%");
> String val = tokenizer.nextToken ();
> String val = tokenizer.nextToken ();
> String val = tokenizer.nextToken ();
> String val = tokenizer.nextToken ();
> String val = tokenizer.nextToken ();
> %>
> <TD> <%= val %> </TD>
> <TD> <%= val %> </TD>
> <TD> <%= val %> </TD>
> <TD> <%= val %> </TD>
> <TD> <%= val %> </TD> </TR>
> <%
> }
> }
> } //this is the one.. I get the no catch here, and the no try on the catch below
> catch (SQLException sql_e)
> { %> </TABLE <BR><BR> <H3>An error has occurred accessing the database. Unable
>to retrieve vals.</H3><BR><BR> <% }
>
> //add val to the table
> %>
> <TR>
> <TD Colspan="2">val</TD><TD> <% val %> </TD>
> </TR>
> </TABLE>
> <BR><BR>
> <%
> }
> %>
>
> <%!
> /**
> Convenience function for determining if a val is current, expired or future.
> @param sDate: start date formatted in the Oracle 'DD-MON-YYYY' format (may
>be null).
> @param eDate: end date formatted in the Oracle 'DD-MON-YYYY' format (may be
>null).
> @return val_EXPIRED if the val is expired.
> val_CURRENT if the val is current.
> val_FUTURE if the val is future.
> */
> public static int valproc (String sDate, String eDate)
> {
> //get our current date
> java.util.Date today = new java.util.Date ();
>
> //determine if this is a current val (and not a future val or expired val)
> //build the dates for this entry using our date format
> java.util.Date startDate = null;
> try
> {
> startDate = df.parse (sDate);
> }
> catch (ParseException p_e)
> { /*ignored...startDate will simply remain null, which is fine */ }
>
> java.util.Date endDate = null;
> try
> {
> endDate = df.parse (eDate);
> r }
> catch (ParseException p_e)
> { /*ignored...endDate will simply remain null, which is fine */ }
> //if the enddate is not null, compare it to the current date. If it is
>less than the
> //current date, this is an expired val.
> if ((endDate != null) && (endDate.before (today)))
> {
> return val_EXPIRED;
> }
>
> //if the startdate is not null, compare it to the current date. If it is
>more than the
> //current date, this is a future val.
> if ((startDate != null) && (startDate.after (today)))
> {
> return val_FUTURE;
> }
>
> //all other cases are current val.
> return val_CURRENT;
> }
>
> %>
>
> </BODY>
> </HTML>
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
--
Erik I Morton
Software Developer
------------------
CommerceHub
http://www.commercehub.com
518-886-0704
21 Corporate Drive
Clifton Park, NY 12065
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets