dcsimg
inserting a serialized image into oracle db
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, May 13, 2002 05:33 AM

hiho i have serialized an image and try to store it as a blob into an oracle8 database try { s.executeUpdate("create table authorinfo(authorinfoid NUMBER(10) PRIMARY KEY, authordate DATE, authorname VARCHAR2(255), action VARCHAR2(255), authorcomment VARCHAR2(255))"); s.executeUpdate("create table image(imageid NUMBER(10) PRIMARY KEY, image BLOB, imagename VARCHAR2(255), imageinfo NUMBER(10))"); s.executeUpdate("create table reportlist(reportid NUMBER(10) PRIMARY KEY, reportname VARCHAR2(255), reportcomment VARCHAR2(255), reportinfo NUMBER(10))"); authorinfoidcounter = 1; iidcounter = 1; try {    More>>

hiho


i have serialized an image and try to store it as a blob into an oracle8 database



try

{


s.executeUpdate("create table authorinfo(authorinfoid NUMBER(10) PRIMARY KEY, authordate DATE, authorname VARCHAR2(255), action VARCHAR2(255), authorcomment VARCHAR2(255))");

s.executeUpdate("create table image(imageid NUMBER(10) PRIMARY KEY, image BLOB, imagename VARCHAR2(255), imageinfo NUMBER(10))");

s.executeUpdate("create table reportlist(reportid NUMBER(10) PRIMARY KEY, reportname VARCHAR2(255), reportcomment VARCHAR2(255), reportinfo NUMBER(10))");


authorinfoidcounter = 1;

iidcounter = 1;


try

{


File file = new File(dir + filename);

FileInputStream fis = new FileInputStream(file);


PreparedStatement pstmt = con.prepareStatement("update image set image=? where imageid=" + iidcounter);

pstmt.setBinaryStream(1, fis, (int)file.length());

pstmt.setString(2, dir + filename);

pstmt.executeUpdate();

pstmt.close();


fis.close();


}

catch (IOException ioe)

{


ioe.printStackTrace();


}

/*catch(FileNotFoundException fnfe)

{


fnfe.printStackTrace();


}

catch(ClassNotFoundException cnfe)

{


cnfe.printStackTrace();


}*/

catch (SQLException sqle)

{


sqle.printStackTrace();


}


//obj2 = convertBytesToObject(buf);


s.executeUpdate("insert into authorinfo values(" + authorinfoidcounter + ", '" + textField4.getText() + "', '" + textField7.getText() + "', '" + textField9.getText() + "', '" + textField12.getText() + "')");

s.executeUpdate("insert into image values(" + iidcounter + ", " + /*(Object)obj2*/ ", '" + textField17.getText() + "', " + authorinfoidcounter + ")");

s.executeUpdate("insert into reportlist values(" + textFieldn.getText() + ", '" + textField2.getText() + "', '" + textField3.getText() + "', " + authorinfoidcounter + ")");


}

catch (SQLException sqle)

{
....
}





if i try this, i get an errormessage, that the bind variable does not exist in the line, where i do:
pstmt.executeUpdate();


any ideas???

thx forewardly,

locutus

   <<Less

Re: inserting a serialized image into oracle db

Posted By:   Anonymous  
Posted On:   Monday, May 13, 2002 06:39 AM

You are using two pstmt.set... when there is only one ? in your statement...
About | Sitemap | Contact