I have a table in my postgres database ie. student which has columns namely name marks1 marks2 where name is varchar(20), marks1 and marks2 is double precision data types.
I am using a prepared statement in a java class
PreparedStatement ps=con.preparestatement("insert into student values(?,?,?);
ps.setString(1,t.getUname());
ps.setDouble(2,t.getUmarks1());
ps.setDouble(3,t.getUmarks2());
status=ps.executeUpdate();
But when a double value is sent it says the above error mentioned in my question.
I have another class where the getters and setters are defined. That is as follows.
public class User {
private String uname;
private double umarks1,umarks2;
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public double getUmarks1() {
return umarks1;
}
public void setUmarks1(double umarks1) {
this.umarks1 = umarks1;
}
public double getUmarks2() {
return umarks2;
}
public void setUmarks2(double umarks2) {
this.umarks2 = umarks2;
}
}
If i change the data type to double it saves a 0 in the database. I want to save a double value. How do I fix this?
I would have thought the best way to do this is to change your Java class to reflect your data model
1) change marks
field and getters/setters to double
2) change PreparedStatement
to setDouble
see setDouble
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.