Error!Urgent!Pls Help.....Thank You

I had the following error with the code below.......anyone pls help me ..... urgent.....I will be really appreciate it......Thank you in advanced.....
I had created two statement,.....one is to select the value of Leave_Reason from a table and store it in the String Leave_Reason after that I need to insert the Leave_Reason variable's value together with other value which input from a form in the previous page....into another table....
But I dun know why I encountered the error below....anyone pls help.....really urgent.....I had tried to solve it for two days already,,,,,
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 86 in the jsp file: /SilkAir/leave_request.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Tomcat 4.1\work\Standalone\localhost\_\SilkAir\leave_request_jsp.java:315: cannot resolve symbol
symbol : variable Leave_Reason
location: class org.apache.jsp.leave_request_jsp
String Query = "INSERT INTO Leave_Application (Emp_Num, Leave_ID, Apply_Date, Leave_Date, Leave_Reason, Leave_Applied, Leave_Status) VALUES ('" + Emp_Num + "', '" + Leave_ID + "', '" Apply_Date "', '" + Leave_Date + "', '" + Leave_Reason + "', '" + Day + "', 'Pending')";
^
1 error
     at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:130)
     at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:293)
     at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:340)
     at org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
     at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:474)
     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:184)
     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
     at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
     at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
     at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
     at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
     at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
     at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
     at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
     at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
     at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
     at java.lang.Thread.run(Thread.java:536)
<request.jsp>
<%@page import="java.sql.*"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.SimpleDateFormat"%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<%
String username = (String)session.getAttribute("username");
%>
<%
//define connection
Connection con = null;
try{
//get the class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//get the connection
     con = DriverManager.getConnection("jdbc:odbc:Database","","");
//please catch your exceptions!
catch(Exception e){
     out.println(e.getMessage());
// form data
String Emp= request.getParameter("txtEmp");
String Leave_ID = request.getParameter("txtReason");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy/MM/dd");
String LeaveDate = request.getParameter("txtLeaveDate");
java.util.Date dateU = sdf.parse(LeaveDate);
java.sql.Date Leave_Date = new java.sql.Date(dateU.getTime());
String Day = request.getParameter("txtDay");
java.text.SimpleDateFormat rd = new java.text.SimpleDateFormat("yyyy/MM/dd");
String ApplyDate = request.getParameter("txtApplyDate");
java.util.Date dateR = rd.parse(ApplyDate);
java.sql.Date Apply_Date = new java.sql.Date(dateR.getTime());
// query statement
ResultSet rs=null;
Statement SQLStatement = con.createStatement();
Statement stm = con.createStatement();
String query = "SELECT DISTINCT LeaveType FROM Leave WHERE Leave_ID ='"+Leave_ID+"'";
rs = stm.executeQuery(query);
if(rs.next())
String Leave_Reason = rs.getString("LeaveType");
else
{    out.println("no results found");
rs.close();
stm.close();
String Query = "INSERT INTO Application (Emp, Leave_ID, Apply_Date, Leave_Date, Leave_Reason, Leave_Applied, Leave_Status) VALUES ('" + Emp_Num + "', '" + Leave_ID + "', '" Apply_Date "', '" + Leave_Date + "', '" + Leave_Reason + "', '" + Day + "', 'Pending')";
// get result code
int SQLStatus = SQLStatement.executeUpdate(Query);
     if(SQLStatus != 0)
     out.println("post successfully.");
     else
     out.println("Problem encountered");
// close connection
SQLStatement.close();
con.close();
%>
</body>
</html>

if(rs.next())
String Leave_Reason = rs.getString("LeaveType");
else
{ out.println("no results found");
rs.close();
stm.close();
String Query = "INSERT INTO Application (Emp, Leave_ID, Apply_Date, Leave_Date, Leave_Reason, Leave_Applied, Leave_Status) VALUES ('" + Emp_Num + "', '" + Leave_ID + "', '" Apply_Date "', '" + Leave_Date + "', '" + Leave_Reason + "', '" + Day + "', 'Pending')";
The Problem is that the variable Leave_Reason is declared as a local variable inside a if block. So the scope of the variable is not visible outside the if block...
Try using something like
String Leave_Reason = "";
if(rs.next())
Leave_Reason = rs.getString("LeaveType");
else
{ out.println("no results found");
This should work...
Hope it helps.
Thanks and regards,
Pazhanikanthan. P

Similar Messages

Maybe you are looking for

  • ALV GRID OUTPUT PROBLEM.

    here i m sending code for u r reviews. i have two tables: pa0002, zfm_handy i have to display alv grid by using these tables, i m getting output but the fields in the table pa0002(nachn,vorna) r not populated i m getting output for the fields those w

  • Forced to use Clear Text Passwords for OD binding

    Running a Tiger Server 10.4.11 as OD master with one Replica. When binding clients to server in Directory Access/LDAPv3, If I "disable Clear Text Passwords," the users can not login. Uncheck this option, everything works fine. Non "Clear Text" passwo

  • How to terminate background job for MRP

    Hi dudes, how to terminate background job set earlier and i want start again with fresh scheduling. as user discontinued using the MRP process. thanks inadvance for quick response. Robert.

  • Can a page-turning SWF to PDF have navigation?

    I'm working on creating a flip-book PDF which needs a Replay button or some other way to get back to the first page OTHER than laboriously clicking back through every single page. In CS4 InDesign, files with Page Turn transistion must be exported as

  • What is iMessage error code:0732-3334-3378?

    What is iMessage error code:0732-3334-3378? Does this mean that iMessage is not supported on my late 2008 MacBook?