Solved

JSP Follow up From Previous

Posted on 2004-03-20
6
260 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven project import to eclipse problems 13 105
logging jar 1 110
some methods private some are not 8 212
countXY challenge 28 151
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Knowing where your website is hosted is as important as the features you receive, the monthly fee, and the support you receive. Due diligence should be done when choosing your next hosting provider.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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