Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

JSP Follow up From Previous

Posted on 2004-03-20
6
262 Views
Last Modified: 2010-04-01
Helo again:
(Part2 - Return of the faulty code)

This returns 1 row to my JSP:

Java Bean:
ResultSet RS             = SQLStmt.executeQuery("SELECT * FROM links WHERE description like'%university%';");

When I call the same method with JSP:

Vector data = databaseBean.GetConnect(strSQL);
(i have output strSQL to the page - it does output university, so i am passing in the correct string)

In my Bean:

      public Vector GetConnect(String strSQL)
      {
          ........
               PreparedStatement ps = ObjConn.prepareStatement("SELECT * FROM links WHERE description like?;");
            ps.setString(1, strSQL);
            ResultSet RS = ps.executeQuery();

I get no rows returned
As you may have guessed from my previous questions I am a complete beginner when it comes to JSP and Beans so is there something i am missing?  Do i need to do anything with the strSQL after it is called into the method?


0
Comment
Question by:Ma7T
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 125 total points
ID: 10642466
>> PreparedStatement ps = ObjConn.prepareStatement("SELECT * FROM links WHERE description like?;");
you need a space between like and ?, and remove the ending ";" (some database will have problem with it).
PreparedStatement ps = ObjConn.prepareStatement("SELECT * FROM links WHERE description like ?");

>> ps.setString(1, strSQL);
it should be
ps.setString(1, "%" + strSQL + "%" );

0
 

Author Comment

by:Ma7T
ID: 10642478
Thanks,
Can you tell me for reference what the % actually does?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10642501
is it working?

% means to match any number of characters. as you said that strSQL does output university. if you just do like 'university', the database only returns record exactly matches university. if you need aal records contains university, you need wildcast match, that is what % for.
0
 

Author Comment

by:Ma7T
ID: 10642519
Thanks a lot.  Its working fine now.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 10642524
glad to know and my pleasure to help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Stuck in Bootstrap WysiHtml Editor 3 42
maven webservice example issue 2 144
by zero exception 10 52
maven disable workspace resolution 1 16
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
Starting your own business is always a daunting process, and for most people it is brand new experience. Avoid the common pitfalls by following these tips to start on the road to success.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question