Saving float values into MySQL database?
I am using MySQL data base need to insert static float values into my table using a Java Bean via (Hibernate). My data does not get inserted even though I use the required float suffix (eg. 0.0F) but the row is inserted as the column data indicates a 开发者_JS百科null.
I need help with getting the correct float values into MySQL as apposed to null(s). Can the community aid me with code that can assist me or direct me to a relevant example to demonstrate how this is done?
1) what do you mean by static
. The object you should be inserting shoudn't be static, since the values of a field can change from one object to another.
2) why do you use the F
suffix. Simply define it in the annotations
@Column(name = "float_value")
private float floatVal;
Or use the .hbm.xml file, with the object mapping still having private float floatVal;
Then simply do:
myObject.setFloatVal(0.0);
session.save(myObject);
精彩评论