Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

search

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try Praful's solution.
 
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
You showed up just in time for the waffles! And this tiny ad:
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
reply
    Bookmark Topic Watch Topic
  • New Topic