When inserting two rows with one column through JDBC batch, the first row is null, the second is 12 - I get an exception. I understand that the driver cannot add null and INTEGER to one column, can anyone bypass is this a misunderstanding?
2 answers
Perhaps something like that. ps.setNull (1, Types.INTEGER);
- Thank you, pushed the right idea. - ezhov_da
|
sqlTo.withBatch (connections.batchSize, queryTo) {ps -> sqlFrom.query (queryFrom) {resultSet ->
//получаем данные о столбцах def rsmt = resultSet.getMetaData() def colCount = rsmt.getColumnCount() def mapColumn = [:] 1.upto(colCount){ def columnName = rsmt.getColumnTypeName(it) def nameColumn = listFieldFrom[it - 1] println nameColumn mapColumn[nameColumn] = columnName println columnName } println mapColumn получаем данные из столбцов while (resultSet.next()) { def listFromResult = [] listFieldFrom.each{ def type = mapColumn[it] def data = resultSet.getObject(it) listFromResult << Sql."$type"(data) } if (counter % connections.batchSize == 0) println "--> set batch: ${counter}" ps.addBatch(listFromResult) counter++ } } }
|