I am having troubles to print a boolean value from a postgresql table in java.
the table:
java=# select * from Materias;
codigo | nombre | contenido | troncal
--------+--------+-----------+---------
1 | | | f
2 | | | f
3 | | | f
4 | | | t
5 | | | t
6 | | | t
now the output using getString
linea = String.format("%-15d %-20s %-10s", resultado.getInt(1), resultado.getString(2), resultado.getString(3));
Codigo Nombre Troncal
1 null
2 null
3 null
4 null
5 null
6 null
the output using getBoolean
linea = String.format("%-15d %-20s %-10s", resultado.getInt(1), resultado.getString(2), resultado.getBoolean(3));
Codigo Nombre Troncal
1 false
2 false
3 false
4 false
5 false
6 false
You've got 4 columns but you're only looking at the first 3! The rs.getX(int) methods index from 1 (confusingly)
I would rewrite your select, btw, to explicitly state the columns and the order that you require them to be returned in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.