0

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[]); を使用するだけで修正されました。

4

2 に答える 2

0

プロファイル ストリームを保存するst.setBinaryStream(byte[])代わりに使用します。st.setObject()

于 2013-10-07T18:40:26.987 に答える