aspose file tools*
The moose likes JDBC and the fly likes Why the string inserted become longer? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Why the string inserted become longer?" Watch "Why the string inserted become longer?" New topic
Author

Why the string inserted become longer?

Li Shangqiang
Greenhorn

Joined: Mar 25, 2001
Posts: 22


I've encounted a strange problem, When i use store procedure to insert a record, the string value expanded to the length of parameter length.


for example, I declared the procedure like this the Database is MS SQLServer, the driver is JDBC-ODBC bridge)
<pre>
CREATE PROCEDURE [up_NewFwxxInfo]
@strBlockName varchar(100),
AS
insert into tbl1(BlockName) VALUES (@strBlockName)
</pre>

and i call the procedure like this:


CallableStatement stmt = conn.prepareCall("{ call up_NewFwxxInfo(?)};
stmt.setString("sky");
stmt.executeUpdate();
</pre>

Then execute a query and get result like this:
<pre>
select '-' + BlockName + "-" FROM Block WHERE BlockID=33
-sky -
</pre>

This show the string inserted expanded to the length of parameter @strBlockName. So I do a trick here:
<pre>
CREATE PROCEDURE [up_NewFwxxInfo]
@strBlockName varchar(100),
AS
select @strBlockName = RTrim(@strBlockName)
insert into tbl1(BlockName) VALUES (@strBlockName)
</pre>
This works, but can anyone give answer?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why the string inserted become longer?