If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Comparing with larger value.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-18-07, 23:45
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
Comparing with larger value.

I have a table with a attribute which i set it to varchar(20),
for example,
create account(
username varchar(20)
);
then i insert some data, then i want to do some comparision,

"select * from account where username="gadsfasdfhaskdfkasjdghfsdaf";

where "gadsfasdfhaskdfkasjdghfsdaf" has more than 20 characters,

when i run the query, error occurs, said that the value is invalid,

how can i solve the problem? is there any way to let it compare with a larger value?
Reply With Quote
  #2 (permalink)  
Old 04-19-07, 03:28
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
the error is because of the quotes
"select * from account where username="gadsfasdfhaskdfkasjdghfsdaf";
should be
"select * from account where username='gadsfasdfhaskdfkasjdghfsdaf' ";
in this case, it does not return an error
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
  #3 (permalink)  
Old 04-19-07, 03:52
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
Yeah, that was just an example,
actually i'm using JDBC and use preparedStatement to generate the query

for example
String name="asdfasq34radfalsdfb93hrlkawdfiah";
String query="select * from account where username=? "
PreparedStatment ps=con.prepareStatment(query);
ps.setString(1,name);
ps.executeQuery();

i've tried the entire query to execute manually in a command prompt,
it works, but it just can't work when i execute the query using PreparedStatement, is it the JDBC error? or other matters?
Reply With Quote
  #4 (permalink)  
Old 04-19-07, 09:41
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
When you prepare the statement, DB2 allocates memory for the parameter based on the column data type, which is VARCHAR(20). If you later try to stuff a longer string into that parameter it won't fit, hence the error.
Reply With Quote
  #5 (permalink)  
Old 04-19-07, 21:36
desmondtanck desmondtanck is offline
Registered User
 
Join Date: Apr 2007
Posts: 23
ic...
so is there any way to solve this problem?
thanks
Reply With Quote
  #6 (permalink)  
Old 04-21-07, 05:12
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What do you reallyyy want to achieve? Comparing a VARCHAR(20) with you value will always be false.

What exactly is the error raised by DB2? I just tried something similar on the command line, and it just worked (and returned 0 rows). No error condition was encountered.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On