Text in if condition is not displayed in the browser
Hello everyone!
Im new wth JSP and facing a problem.
first of all here is the coding of my JSP file:-
<%@page language="java" import="java.sql.*" %>
<%
Connection con=null;
PreparedStatement ps=null;
String Eid=request.getParameter("T1");
String empname=request.getParameter("T2");
String design=request.getParameter("D1");
String dep=request.getParameter("T4");
String addr=request.getParameter("T5");
String mail=request.getParameter("T6");
String birth=request.getParameter("T7");
String join=request.getParameter("T8");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:es123","","");
ps=con.prepareStatement("select * from addition where emp_id='"Eid"'
");
ResultSet rs=ps.executeQuery();
if(!rs.next())
{
PreparedStatement ps1=con.prepareStatement("insert into addition
(emp_id,ename,designation,dept,add,email,dob,doj)"+
"
values('"Eid"','"empname"','"design"','"dep"','"addr"','"mail"','"birth"','"join"')");
ResultSet rs1=ps1.executeQuery();
%>
<H1> SUCCESS DATA SAVED!</H1>
<% }
else { %>
<H1>CANNOT ADD!<br> EMPLOYEE ID ALREADY EXIST IN THE DATABASE!</H1>
<% }
}
catch(Exception e){}
finally{
try{
if(con!=null){
ps.close();
con.close();
}
}
catch(Exception r){}
}
%>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title><jsp database connection></title>
</head>
<body>
<a href="select1.jsp">click to move back</a>
</body>
</html>
--------------------------------------------------------------------------------
The problem I am facing is that when an entry successfully gets saved
in the database( when i refresh access a new row is added
successfully) but the browser doesnot displays this- " SUCCESS DATA
SAVED! "
and for the else case it works fine and displays CANNOT ADD! EMPLOYEE
ID ALREADY EXIST IN THE DATABASE!.
Im confused else condition is working properly but if condition is
not. I want "SUCCESS DATA SAVED " to be displayed in the browser
window.
My Web Browser- IE-7
Server- Tomcat6.0
DB- MS ACCESS 2007
JDK- JDK1.6