Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Display message using java servlet

843842Dec 29 2008 — edited Dec 31 2008
hi friends,
this is akshatha
i am developing telphone directory using jsp page
I attached small program of search either name or desingation in servlet
this program is working fine but very small error
if anybody knows can u correct it
1. when i search name from the data base if it is there in database and i will diaplay in result1.jsp page
2. if data is not there in database it should display "search item doesnot exist" in result1.jsp page

The 1st one is working fine
the 2nd one have problem of dispaly search item doesnot exist



ArrayList arraylist=new ArrayList();


if(!(Surname.equals("") || Designation.equals("")))
{

try
{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

connection = DriverManager.getConnection("jdbc:odbc:istrac");

statement=connection.createStatement();

String sql="SELECT * FROM istrac where Surname LIKE ? OR Designation LIKE ? ORDER BY Surname ASC";

Surname=Surname+"%";
Designation=Designation+"%";

PreparedStatement ps=connection.prepareStatement(sql);

ps.setString(1, Surname);

ps.setString(2, Designation);


rs=ps.executeQuery();


while(rs.next())
{


bean vb=new bean();


vb.setSurname(rs.getString(1));


vb.setTitle(rs.getString(2));

vb.setFirstName(rs.getString(3));

vb.setSecondName(rs.getString(4));

vb.setPhoneNumber1(rs.getString(10));

vb.setPhoneNumber2(rs.getString(11));


vb.setMobileNumber1(rs.getString(12));

vb.setMobileNumber2(rs.getString(13));

vb.setPagerNumber(rs.getString(14));
vb.setFaxNumber(rs.getString(15));


vb.setEmail(rs.getString(16));

vb.setDesignation(rs.getString(17));

vb.setCenter(rs.getString(18));

arraylist.add(vb);


}


session.setAttribute("arraylist", arraylist);
RequestDispatcher rd;
rd=request.getRequestDispatcher("result1.jsp");
rd.forward(request, response);

}



catch(Exception e1)

{


out.println("search item could not found");


e1.printStackTrace();

}


}
else
{
response.sendRedirect("Error.jsp");
System.out.println("Search item could not found");
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 28 2009
Added on Dec 29 2008
3 comments
275 views