Triming a setString into a PreparedStatement

Hi there!

I want to store one string into a table and, in spite of string has no spaces, when I check it out on the table it has a lot of spaces after the word. I am using SQLServer 2000.

Here is the code:

public void insert(String name) throws SQLException {

try {

this.dbConn = daoFac.getConn();

String sqlStr = "INSERT INTO " + res.getString("table") +

" (name)" +

" VALUES (?)"; //name field is varchar(50)

prStm = dbConn.prepareStatement(sqlStr, ResultSet.TYPE_SCROLL_INSENSITIVE,

ResultSet.CONCUR_UPDATABLE);

prStm.setString(1, name.trim()); //Trim does not work!!!

prStm.execute();

}

finally {

daoFac.closeConn();

}

}

I have try with literal expresions as "word" but it does not work either. When I check it on the table it appears like "word " It puts as many spaces as it need to reach the length of "name" field (varchar(50))

Anyone knows how to fix it?

Thanks a lot for your help

LJ

[1037 byte] By [lj_garcia] at [2007-9-30 11:05:11]
# 1
Are you sure the field is a varchar and not a char?
philip_ross at 2007-7-3 22:40:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...