Solved

JSP Follow up From Previous

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now