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

