Java save JavaObjects in sql database -


i'm trying save java object in sql database im getting errory cannot solve ...

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 users(name,pw,profile) values(?,?,?)");         ps.setstring(1, name);         ps.setstring(2, pw);         ps.setobject(3, (object)profile);         ps.executeupdate();} 

and says

sql exception : unknown sql type preparedstatement.setobject (sql type=1111 @ sun.jdbc.odbc.jdbcodbcpreparedstatement.setobject(unknown source) 

hope can me :d thx in advance

ps profile class

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; } 

}

fixed using ps.setbytes(3,byte[]);

use st.setbinarystream(byte[]) instead of st.setobject() save profile stream.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -