Solved

JSP Follow up From Previous

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fisheye tool 2 104
J2SE 5.0 metadata 1 51
SimpleDateFormat.parse examples 19 87
Prevent Firefox page from going to the background when clicking a spreadsheet link 17 67
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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