Results 1 to 3 of 3

Thread: VARCHAR problem

  1. #1
    Join Date
    May 2002
    Posts
    2

    Arrow Unanswered: VARCHAR problem

    Hi,
    Can anyone solve this......
    I am working with a SQL Server database. I insert data into a column of datatype VARCHAR and size 50. But the data i insert is of say length 10. When it is inserted , it is done so with trailing blank spaces padded till the length is 50. The driver i use is jdbc:odbc. Is it a problem with SQL Server or the driver? No such problem comes for MS-ACCESS.
    B'coz of this when that data is retreived, it has trailing blank spaces, which gives me problem afterwards.
    Jyothi.

  2. #2
    Join Date
    Nov 2001
    Posts
    36
    Just trim (ltrim | rtrim ) the value before inserting it into the database from the application. There is no problem with the database nor with the drivers. I think that should do.

  3. #3
    Join Date
    May 2002
    Posts
    2

    VARCHAR problem - a possible solution i guess

    Originally posted by Decastod
    Just trim (ltrim | rtrim ) the value before inserting it into the database from the application. There is no problem with the database nor with the drivers. I think that should do.
    Ok, i found a solution i guess. Well, after trimming also this problem does not seem solved. The problem is with the jdbc:odbc driver , b'cos odbc takes varchar as char only(since it is common for many dbs and so some dbs may not have varchar type) and so it must be appending the spaces. However here was a workaround ...

    PreparedStatement oprdStmtUser;
    oprdStmtUser.setObject(iIndex,szValue,Types.VARCHA R);
    instead of using
    oprdStmtUser.setString(iIndex,szValue);

    When Types.VARCHAR is specified, this problem does not seem to arise.

Posting Permissions

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