Hi,
I am using the jdbcTemplate.batchUpdate() method on a Sybase database and because I am reading from a unrealiable data source, I have some bad data (outside unicode 16bit) to insert in the DB like "âæ?5B±*".
The Sybase manual say that I need to set some properties of the database session. I can do this in executing "set char_convert on with no_error" on the PreparedStament.
http://manuals.sybase.com/onlinebook...28381;pt=14594
So, basically It seems that I should do:
But when I insert this code in the place I guess it should be, I get this error:Code:preparedStatement.execute("set char_convert on with no_error");
Code:org.springframework.jdbc.UncategorizedSQLException: (executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$SimplePreparedStatementCreator@70fe3f63]): encountered SQLException [JZ0S3: The inherited method execute(String) cannot be used in this subclass.]; nested exception is java.sql.SQLException: JZ0S3: The inherited method execute(String) cannot be used in this subclass.
The code I use is this one. I am following the example of Spring in Action, page 148 (Listing 4.8 ):
So does anyone know how to execute a query on the PreparedStatement passed in the setValues() or elsewhere? I just need to execute "set char_convert on with no_error"before I update data in the database using the batchUpdate..Code:public void updateBatchRecord(String sql, final List objList){ BatchPreparedStatementSetter setter = null; setter = new BatchPreparedStatementSetter(){ public int getBatchSize(){ return objList.size(); } public void setValues(PreparedStatement ps, int index) throws SQLException { ps.execute("set char_convert off"); <----- EXCEPTION HERE Iterator it = ((List)objList.get(index)).iterator(); int i=0; while(it.hasNext()){ i++; Object obj = (Object)it.next(); ps.setObject(i, obj); } } }; // Finally, I call the Spring DAO and do a simple //->JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); //->jdbcTemplate.batchUpdate(sql,setter); SpringUtil.getSybaseDataAccess().updateBatchUpdate(sql,setter); }
Any idea?
Thanks,
Etienne.


Reply With Quote