File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "Problem in Query" Watch "Problem in Query" New topic
Author

Problem in Query

prriya pratheep
Greenhorn

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 +"'";
else
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
Greenhorn

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

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

EX:

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
Greenhorn

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Query
 
Similar Threads
NX: Search requirement
Compare Two Text fields in Swing
Bypassing ActionForm by using a query string
Unable to retrive the proper data from a query string inside jsp page
Validating the Data File