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. On Jul 27, 12:37 pm, shanu <> wrote:
    > Hello everyone!
    > Im new wth JSP and facing a problem.


    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

    > <H1> SUCCESS DATA SAVED!</H1>


    Stop SHOUTING at your users. They are not DEAF!

    > catch(Exception e){}


    ..and stop swallowing exceptions in broken code.
    <http://pscode.org/javafaq.html#stacktrace>

    --
    Andrew Thompson
    http://pscode.org/
     
    Andrew Thompson, Jul 27, 2008
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -
    Replies:
    12
    Views:
    986
    Remon van Vliet
    Jun 15, 2005
  2. HockeyFan
    Replies:
    2
    Views:
    503
    HockeyFan
    Dec 7, 2006
  3. boney
    Replies:
    1
    Views:
    750
  4. Trygve Laugstøl
    Replies:
    4
    Views:
    5,240
    rickman
    Jan 24, 2011
  5. sandhu
    Replies:
    1
    Views:
    1,030
    Alvin Bruney [MVP]
    May 17, 2007
  6. LetMeDoIt

    ASP code not displayed on web browser

    LetMeDoIt, Dec 24, 2006, in forum: ASP General
    Replies:
    1
    Views:
    206
    Evertjan.
    Dec 24, 2006
  7. Bill W.
    Replies:
    13
    Views:
    562
    Phillip Gawlowski
    May 9, 2011
  8. karambol

    Text Not Being Displayed

    karambol, Oct 27, 2003, in forum: Javascript
    Replies:
    6
    Views:
    173
    karambol
    Oct 27, 2003
Loading...