Text in if condition is not displayed in the browser

Discussion in 'Java' started by shanu, Jul 27, 2008.

  1. shanu

    shanu Guest

    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:eek:dbc: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
     
    shanu, Jul 27, 2008
    #1
    1. Advertisements

  2. If that problem is with spelling, note that FF will
    highlight words it does not understand, in red. This
    helps when posting via GG, since things like 'Im' and
    'wth' are underlined.

    Note also that a good group for people new to Java,
    is comp.lang.java.help
    Stop SHOUTING at your users. They are not DEAF!
    ..and stop swallowing exceptions in broken code.
    <http://pscode.org/javafaq.html#stacktrace>
     
    Andrew Thompson, Jul 27, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.