Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

else block is not processed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im new with jsp.. ill be grateful if anyone can help me with this!! thanks in advance!

The else condition is not getting processed in the jsp file but if condition processes fine!
first, here is the code of the html file:-
<html>

<body bgcolor="#ffffff">

<form name="mod" method="post" action="emp_verify.jsp">
<h1 align="center">Modify Employee</h1>
<h2 align="left">Enter The Employee Id to modify the details:
<input type="text" name="T1"> </h2>
</form>
<p align="left"><input type="submit" value="Submit" name="sub1"> </p>
<hr>
<p align="left">  </p>

</body>
</html>

NOW THIS IS THE CODING OF emp_verify.jsp:-

<%@page language="java" import="java.sql.*" %>

<html>
<body>

<%
String id=request.getParameter("T1");


try{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:es123","","");


PreparedStatement ps=con.prepareStatement("select * from addition where emp_id=?");
ps.setString(1,id);

ResultSet rs=ps.executeQuery();

if (rs.next()) {
%>
<!-- when successful page turns to emp_about.jsp--!>

<jsp:forward page="emp_about.jsp" />

<% } else { %>

<!--but when unsuccessfull this is not displayed --!>

EMPLOYEE ID DOES NOT EXIST!

<% } %>
<% }
catch(Exception e){} %>

</body>
</html>

when entry is found, control is properly transfered to emp_about.jsp, but
when entry is not found in the database the code in else condition does not shows up!

please help me with this, im new in jsp!!!
thank you!!!
[ July 25, 2008: Message edited by: Sushant Gulati ]
 
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

Using a title of "help me" isn't very descriptive.

You can go back and change your post to add a more meaningful subject by clicking the .
 
Sushant Gulati
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.. as you can see i have changed the subject content.
actually i m new to this trend of posting topics!
 
Bear Bibeault
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's ok, we all start somewhere. Something esle you should do is to be sure to use UBB code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
Bear Bibeault
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a beginner in JSP, you should immediately be advised that putting Java code (especially database code) in a JSP is considered a very poor practice. Java code is much easier to deal with when factored into beans and model classes.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swallowing exceptions is also pretty bad.



Herman
[ July 25, 2008: Message edited by: Herman Scheltinga ]
 
Sushant Gulati
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have already done a course in core java where i studied jdbc too. But advanced java will come in next semester in my course so i have No idea about java beans and servlets!
 
Fire me boy! Cool, soothing, shameless self promotion:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!