我正在尝试在我的 SQL 数据库中保存一个 Java 对象,但我遇到了一个我无法解决的错误......
stat.executeUpdate("CREATE Table users( id INT UNIQUE NOT NULL AUTO_INCREMENT,name char(50), pw char(50), messages LONGBLOB, profile LONGBLOB )");
. . .
public static void registerNewUser(String name , String pw , Profile profile){PreparedStatement ps=null;
ps = con.prepareStatement("insert into users(name,pw,profile) VALUES(?,?,?)");
ps.setString(1, name);
ps.setString(2, pw);
ps.setObject(3, (Object)profile);
ps.executeUpdate();}
最后它说
SQL Exception : Unknown SQL Type for PreparedStatement.setObject (SQL Type=1111
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setObject(Unknown Source)
希望有人可以帮助我:D Thx 提前
ps配置文件类
public class Profile implements Serializable{
private String name;
private int idNumber;
private byte[] picture;
private String password;
public Profile(String n, int i, byte[] p, String pw) {
this.name = n;
this.idNumber = i;
this.picture = p;
this.password = pw;
}
public String getProfileName(){
return this.name;
}
public int getIDNumber(){
return this.idNumber;
}
public byte[] getProfilePicture(){
return this.picture;
}
public String getPassword(){
return this.password;
}
public void setIDNumber(int number){
this.idNumber = number;
}
}
仅使用 ps.setBytes(3,byte[]);