aspose file tools*
The moose likes JDBC and the fly likes query failing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "query failing" Watch "query failing" New topic
Author

query failing

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

i have a strange problem when i am searching with my data base o a column by using java.
My problem is i am using a search which has one field t search like "starts with" or "ends with" or "contains" of a word i am getting user values in a servlet and and building a query based on that my query is

upto now it's fine. i executed this querying my database it is giving 1 record but in my java program it is giving no record why?
My Java code is


Please help me on this
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

well if you have included the whole of your method, nowhere do you tell the statement the actual sql string
can you show us how you make the Query

and to improve your select where maw_desc like 'a%r'
mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 244

k there is nothing wrong with my query generation. some stupid guy entered space after the word so the search is getting failed. but in my sql when execute same query it is automatically trimming space at the end showing result why?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

mallikarjun dontamsetti wrote:k there is nothing wrong with my query generation. some stupid guy entered space after the word so the search is getting failed. but in my sql when execute same query it is automatically trimming space at the end showing result why?


find out how your databases does right trim and do that on the column in the select.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

mallikarjun dontamsetti wrote:k there is nothing wrong with my query generation. some stupid guy entered space after the word so the search is getting failed. but in my sql when execute same query it is automatically trimming space at the end showing result why?


have you learnt all of this information since the 1st post, as I find the tone of this message actually quite rude.
You showed us half a snippet of code, said it wasn't returning rows.

As to why your browser is ignoring trailing spaces, how the hell are we supposed to know.
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1851
    
  16

mallikarjun dontamsetti wrote:... but in my sql when execute same query it is automatically trimming space at the end showing result why?


Depends how you are viewing the query results. If you are viewing them via a web browser, it may be that the browser is seeing the output values as normal HTML strings and collapsing the whitespace. And you should probably be stripping trailing spaces from your input values instead of relying on the user to get it right. Garbage in, garbage out.

In general, you should write and test your SQL directly on the database e.g. via your DB's SQL shell or using a proper DB tool (TOAD, SQLDeveloper etc).


No more Blub for me, thank you, Vicar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query failing