How to set a char in a Preparedstatement?

Asked

Viewed 617 times

4

My typical variable is a char how to set this in Preparedstatement ?

PreparedStatement ps = conexao.prepareStatement(sql);
ps.setString(1, veiculo.getTipoCombustivel());

inserir a descrição da imagem aqui

  • 2

    Use ps.setString(1, String.valueOf(veiculo.getTipoCombustivel()));

  • Thanks, it worked out !

1 answer

3


Exactly this way, however it is necessary that the type passed is a String.

Therefore:

ps.setString(1, String.valueOf(veiculo.getTipoCombustivel()));

Type mapping:

JDBC Type              Java Type
-------------------------------------------
CHAR                   String
VARCHAR                String
LONGVARCHAR            String
NUMERIC                java.math.BigDecimal
DECIMAL                java.math.BigDecimal
BIT                    boolean
BOOLEAN                boolean
TINYINT                byte
SMALLINT               short
  • 1

    @Jarwin Convert your variable char for String. Luiz, if you can update your answer by adding this information, to reflect the update in the question. Then it is complete. Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.