Question

I am trying to upload a file to DB2 Clob column. I am getting the file from user using FormFile. This FormFile object is sent to DAO layer where it has to be inserted. My DAO layer logic is given below,

public int uploadRequestDocument(final int requestId, final FormFile requestFile, final String userId) throws EfoneException{
int updatedRowCount = 0;
String sqlQuery = Constants.GFONO_QUERY_ADD_GFONO_REQUEST;
LobHandler lobHandler = new DefaultLobHandler();
final InputStreamReader requestDocumentReader = new InputStreamReader(requestFile.getInputStream());

updatedRowCount = getJdbcTemplate().execute(sqlQuery, new AbstractLobCreatingPreparedStatementCallback(lobHandler) {
@Override
protected void setValues(PreparedStatement stat, LobCreator lobCreator)throws SQLException, DataAccessException {
 stat.setString(1, "1");
 stat.setString(2, "Test");
 stat.setString(3, userId);
 stat.setString(4, userId);
 stat.setInt(5, requestId);
 lobCreator.setClobAsCharacterStream(stat, 6, requestDocumentReader, requestFile.getFileSize());
}
});

I tried the below options too but was not fruitful,

stat.setCharacterStream(6, requestDocumentReader, requestFile.getFileSize());
stat.setCharacterStream(6, requestDocumentReader, MAX_SIZE);

I am always getting the below error message,

org.springframework.dao.DataIntegrityViolationException: 
PreparedStatementCallback; SQL 
[insert into GFONO.GFONO_REQUEST_DOC (rqst_doc_num, rqst_doc_loc_num, last_change_userid, create_userid, create_tmstp, last_change_tmstp, efa25_seq_num, rqst_doc)
values (?,?,?,?,CURRENT TIMESTAMP, CURRENT TIMESTAMP, ?,?)];
DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null;
nested exception is com.ibm.db2.jcc.a.SqlException: DB2 SQL error: SQLCODE: -302, SQLSTATE: 22001, SQLERRMC: null
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)

Please suggest on what I am missing and help me resolve this issue. Thanks in advance

Was it helpful?

Solution

This error code says:

THE VALUE OF INPUT VARIABLE OR PARAMETER NUMBER position-number IS INVALID OR 
TOO LARGE FOR THE TARGET COLUMN OR THE TARGET VALUE

You said that you try to insert file into CLOB. Try to use BLOB...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top