jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Problem when inserts data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem when inserts data" Watch "Problem when inserts data" New topic

Problem when inserts data

Luong Nguyen
Ranch Hand

Joined: May 06, 2001
Posts: 31
Hi all,
This is my problem: I have a database. I use JDBC with MS SQL on Windows 2000 to access the database. In my database, I create a table and the table has a field which is VARCHAR(50). When I insert data into the table, even if the length of the data is less than 50 but the value of the field is always 50 characters.
Please help me! Thanks in advance.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

which jdbc driver are you using? Are there any known bugs? Are you sure it is a VARCHAR field in the DB and not a CHAR?? What is the length of the String before the insert to the DB?
very puzzling!
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
One thing you could try is trimming the String variable before sending it to the DB via JDBC (use the <code>trim()</code> of the String class).
May not make any difference, but just a thought...
The first thing, as always, is to figure our WHERE this behaviour is taking place (i.e. is it in the Java code, the JDBC call, the stored proc/SQL, or the database itself?)

"One good thing about music - when it hits, you feel no pain"
Bob Marley

"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem when inserts data
It's not a secret anymore!