On Mon, 14 Nov 2011, David Pinheiro wrote:
>
> Bug reference: 6292
> PostgreSQL version: 8.4
> Description: java.sql.PreparedStatement.setNull() throws
> PSQLException
> Details:
>
> I'm trying to make:
> java.sql.PreparedStatement.setNull(1,java.sql.Types.NULL);
>
> org.postgresql.util.PSQLException: ERROR: column "number_column" is of type
> integer but expression is of type character varying
> Hint: You will need to rewrite or cast the expression.
>
>
> My code is something like:
> if (String.valueOf(input_field) == "null"){
> statement.setNull(1, java.sql.Types.NULL);
> } else {
> statement.setObject(1, valor);
> }
> statement.executeUpdate();
>
I don't think your problem is with setNull, I think your problem is
actually with the setObject branch of your if statement. If the
valor variable is a String, the JDBC driver is assigning it a string
type. You may want to do setObject(1, valor, Types.INTEGER) or
convert it prior to doing the setObject call to an appropriate
numeric type.
Kris Jurka
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера