'setBoolean() method of java.sql.PreparedStatement
As per the oracle documentation -
https://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html#setBoolean(int,%20boolean)
setBoolean(int parameterIndex,boolean x)
method Sets the designated parameter to the given Java boolean value. The driver converts this to an SQL BIT or BOOLEAN value when it sends it to the database.
Here is there any way to know when the value will be stored as SQL BIT? and when will it store as BOOLEAN?
I am using oracle database, I have used this method passing the value as true(Java Boolean) and the value getting stored in database is 1 instead of Y. What could be the reason?
Solution 1:[1]
T.J. Crowder's answer is correct.
CREATE TABLE TEST_1
(
MEAL CHAR(1) CONSTRAINT MEAL_CONSTRAINT
CHECK (MEAL IN ('Y', 'N'))
);
Output:
Table: TEST_1
Column name: MEAL
Data type: CHAR(1 BYTE)
Nullable: Yes
Bean:
private boolean meal;
public Boolean getMeal(){
return meal;
}
public void setMeal(Boolean meal){
return this.meal = meal;
}
And then use,
preparedStatement.setString(indexOfMealCol, getMeal() ? "Y" : "N");
Note:
- Providing any other value than
YorN, it will throw error - Null value accepted
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
