Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2007
    Posts
    23

    Unanswered: 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?

  2. #2
    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

  3. #3
    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?

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    Join Date
    Apr 2007
    Posts
    23
    ic...
    so is there any way to solve this problem?
    thanks

  6. #6
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •