File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Problem in Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem in Query" Watch "Problem in Query" New topic

Problem in Query

prriya pratheep

Joined: Jun 10, 2008
Posts: 22
Hi friends,

I want to do one jdbc program which runs the query with wild characters.

Before that in my table filed values are like "ARVOD TEC ", that is a lot of space at the end.

In jsp page if the user enter AR* it should display all the data starts with AR
if the user enter *VOD it should display all the data ends with vod.

I wrote the code to check if the * is at last.In this code strmpn contains is field value

for (int i=0; i < strmpn.length(); i++)
if (strmpn.charAt(i)=='*')
flag = true;
String replaces =strmpn.replace('*','%');
if (flag)
Query = Query +" MPN like '"+replaces +"'";
Query = Query +" MPN = '"+replaces +"'";

If the * is at the end it is working fine.

What is my problem is i want to check at the begining too
Since field values contains lot of space at the end , for example "ARC ",I am not able to get the result...

Please help me how to solve this problem...

Thanks & Regards
Casttro Francis

Joined: Oct 08, 2008
Posts: 25
HI Priya,

Use Trim in the Query itself. It will work..


trim(' ARVOD TEC ')

You are using Oracle or DB2 ?? :thumb:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand....
prriya pratheep

Joined: Jun 10, 2008
Posts: 22
I am using MYSQL...

I am using select st and display the value(this is for search form)

My code is

Thanks for the reply
Thanks and Regards
It is sorta covered in the JavaRanch Style Guide.
subject: Problem in Query
It's not a secret anymore!