File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

search

 
jyotsana dang
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a searching facility iam trying to implement in my jsp application. It has 2 fields that is the firstname and lastname and on that basis a page will be displayed containing the matching names and on clicking on the particular name one can see the home page of the person.
can anyone give me some idea about the same..
 
jyothsna kumari
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai,
I understood what you want to do.But inorder to help you, you should clearly
specify in what way you are doing and where you are getting the problem.
Jyothsna
 
jyotsana dang
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey!! same names .. good coincidence..
iam trying to display names in my page.. like if the user enters anoo in the name field ..then all the names whihc have 'anoo' in the beginning or in the middle or end will be displayed.
in my sql i write query as select * from table where fname like '%anoo%' and iam able to get the results but in my jsp page iam not able to
i have written the query like
rs = stmt.executeQuery("select fname,lname from login where fname like %'"+fname+"'% or lname like %'"+lname+"'%");
iam getting a null pointer exception in this..
can u help me out in this..
and have a great life ahead!!
 
jyothsna kumari
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
in my sql i write query as select * from table where fname like '%anoo%' and iam able to get the results but in my jsp page iam not able to

so you are getting the results....
rs = stmt.executeQuery("select fname,lname from login where fname like %'"+fname+"'% or lname like %'"+lname+"'%");
iam getting a null pointer exception in this..

so you are getting the exception.
i am not understanding you help for the query or getting the results to jsp page.
Jyothsna
 
jyotsana dang
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the sql query analyzer the records are displayed . but when i write the same query in my jsp page..iam not getting any records in my next page. and the tomcat window gives a null pointer exception..
where does the error lie?? iam tired of debugging!
 
jyotsana dang
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my code:

<%!
Connection con;
java.sql.Statement stmt;
ResultSet rs;
%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc:mech_iit");
stmt = con.createStatement();
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
System.out.println(con);
System.out.println(stmt);

System.out.println("select * from login where fname like %'"+fname+"'% or lname like %'"+lname+"'%");
if(rs.next())
{
rs.close();

rs = stmt.executeQuery("select fname,lname from login where fname like %'"+fname+"'% or lname like %'"+lname+"'%");

while(rs.next())
{
fname = rs.getString("fname") ;
lname = rs.getString("lname");
%>
<table border="1" width="400">
<tr><td><%=fname %></td>
<td><%=lname %></td>
</tr>
<%
}
}
else
{
%>
<b>Sorry there is no any match.<b><br>

<%
}
}
catch(Exception e)
{
System.out.println(e);
}
%>
</table>
 
Praful Thakare
Ranch Hand
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
can you tell,why have you written these lines

This line will always throw nullpointer exception as rs is null before execution of this statement.
removing if statement will solve your problem......
Njoy Serching...
Praful
 
jyothsna kumari
Ranch Hand
Posts: 108
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try Praful's solution.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic