@Test public void dataTruncationTranslation() { SQLExceptionTranslator sext = new SQLErrorCodeSQLExceptionTranslator(ERROR_CODES); SQLException dataAccessEx = new SQLException("", "", 5); DataTruncation dataTruncation = new DataTruncation(1, true, true, 1, 1, dataAccessEx); DataAccessResourceFailureException daex = (DataAccessResourceFailureException) sext.translate("task", "SQL", dataTruncation); assertEquals(dataTruncation, daex.getCause()); }
printWriter.println(header + " Index = " + ((java.sql.DataTruncation) e).getIndex()); printWriter.println(header + " Parameter = " + ((java.sql.DataTruncation) e).getParameter()); printWriter.println(header + " Read = " + ((java.sql.DataTruncation) e).getRead()); printWriter.println(header + " Data size = " + ((java.sql.DataTruncation) e).getDataSize()); printWriter.println(header + " Transfer size = " + ((java.sql.DataTruncation) e).getTransferSize());
public static void displayError(DataTruncation dataTruncation) { if (dataTruncation != null) { System.out.println("Data truncation error: "); System.out.println(dataTruncation.getDataSize() + " bytes should have been "); if (dataTruncation.getRead()) { System.out.println("Read (Error:) "); } else { System.out.println("Written (Error:) "); } System.out.println(dataTruncation.getTransferSize() + " number of bytes of data actually transferred."); } }
private boolean checkDataMappingWarning(ResultSet rs, int columnIndex) throws SQLException{ boolean dataMapping = false; SQLWarning w = rs.getWarnings(); if(w!=null){ do{ if(w.getSQLState().equals("01004") && ((java.sql.DataTruncation)w).getDataSize() == -1 && ((java.sql.DataTruncation)w).getTransferSize() == -1 && ((java.sql.DataTruncation)w).getIndex() == columnIndex) dataMapping = true; w=w.getNextWarning(); }while(w!=null); } return dataMapping; }
printWriter.println(header + " Index = " + ((java.sql.DataTruncation) e).getIndex()); printWriter.println(header + " Parameter = " + ((java.sql.DataTruncation) e).getParameter()); printWriter.println(header + " Read = " + ((java.sql.DataTruncation) e).getRead()); printWriter.println(header + " Data size = " + ((java.sql.DataTruncation) e).getDataSize()); printWriter.println(header + " Transfer size = " + ((java.sql.DataTruncation) e).getTransferSize());
DataTruncation e2 = (DataTruncation) exception2; return (e1.getDataSize() == e2.getDataSize()) && (e1.getIndex() == e2.getIndex()) && (e1.getParameter() == e2.getParameter()) && (e1.getRead() == e2.getRead()) && (e1.getTransferSize() == e2.getTransferSize());
public void setString(String value) throws SQLException { byte[] data = setStringForced(value); if (value == null) return; assert data != null : "Expected non-null data here"; if (data.length > fieldDescriptor.getLength() && !isSystemTable(fieldDescriptor.getOriginalTableName())) { // special handling for the LIKE ? queries with CHAR(1) fields if (!(value.length() <= fieldDescriptor.getLength() + 2 && (value.charAt(0) == '%' || value.charAt(value.length() - 1) == '%'))) throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, data.length, fieldDescriptor.getLength()); } }
public void setString(String value) throws SQLException { byte[] data = setStringForced(value); if (value == null) return; assert data != null : "Expected non-null data here"; if (data.length > fieldDescriptor.getLength() && !isSystemTable(fieldDescriptor.getOriginalTableName())) { // special handling for the LIKE ? queries with CHAR(1) fields if (!(value.length() <= fieldDescriptor.getLength() + 2 && (value.charAt(0) == '%' || value.charAt(value.length() - 1) == '%'))) throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, data.length, fieldDescriptor.getLength()); } }
postWarning(new DataTruncation(parameterIndex, true, true, -1, -1)); postWarning(new DataTruncation(parameterIndex, true, true, actualSize, actualSize - truncated));
postWarning(new DataTruncation(columnIndex, false, true, -1, -1)); postWarning (new DataTruncation (columnIndex, false, true, actualSize, actualSize - truncated));
@Override public void setBytes(byte[] value) throws SQLException { if (value == null) { setNull(); return; } if (value.length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, value.length, fieldDescriptor.getLength()); } setFieldData(value); }
@Override public void setBytes(byte[] value) throws SQLException { if (value == null) { setNull(); return; } if (value.length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, value.length, fieldDescriptor.getLength()); } setFieldData(value); }
@Override public void setBytes(byte[] value) throws SQLException { if (value == null) { setNull(); return; } if (value.length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, value.length, fieldDescriptor.getLength()); } setFieldData(value); }
@Override public void setBytes(byte[] value) throws SQLException { if (value == null) { setNull(); return; } if (value.length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, value.length, fieldDescriptor.getLength()); } setFieldData(value); }
@Override protected void setBinaryStreamInternal(InputStream in, long length) throws SQLException { if (in == null) { setNull(); return; } if (length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length, fieldDescriptor.getLength()); } try { setBytes(IOUtils.toBytes(in, (int) length)); } catch (IOException ioex) { throw new TypeConversionException(BINARY_STREAM_CONVERSION_ERROR); } }
@Override protected void setBinaryStreamInternal(InputStream in, long length) throws SQLException { if (in == null) { setNull(); return; } if (length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length, fieldDescriptor.getLength()); } try { setBytes(IOUtils.toBytes(in, (int) length)); } catch (IOException ioex) { throw new TypeConversionException(BINARY_STREAM_CONVERSION_ERROR); } }
@Override protected void setCharacterStreamInternal(Reader in, long length) throws SQLException { if (in == null) { setNull(); return; } if (length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length, fieldDescriptor.getLength()); } try { setString(IOUtils.toString(in, (int) length)); } catch (IOException ioex) { throw new TypeConversionException(CHARACTER_STREAM_CONVERSION_ERROR); } } }
@Override protected void setCharacterStreamInternal(Reader in, long length) throws SQLException { if (in == null) { setNull(); return; } if (length > fieldDescriptor.getLength()) { throw new DataTruncation(fieldDescriptor.getPosition() + 1, true, false, (int) length, fieldDescriptor.getLength()); } try { setString(IOUtils.toString(in, (int) length)); } catch (IOException ioex) { throw new TypeConversionException(CHARACTER_STREAM_CONVERSION_ERROR); } } }
number == 9502))) { SQLException tmp = e; e = new DataTruncation(-1, false, false, -1, -1);
@Test public void testDataTruncationException() throws Exception { validateErrorInformation( exceptionHandler.handlePersistenceException(getPersistenceException(new DataTruncation(1, true, true, 5, 10)), new MockHttpServletResponse()), HttpStatus.BAD_REQUEST, false); }