How do I set a char in a PreparedStatement?

4

My FuelType variable is a char how to set this in the PreparedStatement?

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

    
asked by anonymous 02.06.2015 / 19:18

1 answer

3

Exactly this way, however, it is necessary that the passed type be 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
    
02.06.2015 / 19:22