Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JSP Follow up From Previous

Posted on 2004-03-20
6
Medium Priority
?
269 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
[X]
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
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

618 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