The Artima Developer Community
Sponsored Link

Java Answers Forum
problem inserting blob in oracle database

4 replies on 1 page. Most recent reply: May 16, 2002 1:20 AM by locutus

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
locutus

Posts: 6
Nickname: locutus
Registered: May, 2002

problem inserting blob in oracle database Posted: May 14, 2002 4:34 AM
Reply to this message Reply
Advertisement
hiho,

when i try to insert a serialised image/xml-file into an oracle database, the value that is inserted is always "null".
it would be very nice, if somebody could help me with that.

my code:

try
{
s.executeUpdate("create table reportsection(sectionid NUMBER(10) PRIMARY KEY, sectiontemplateid NUMBER(10), reportid NUMBER(10), singledatasection NUMBER(1), sortorder NUMBER(10))");
s.executeUpdate("create table sectionlist(sectiontemplateid NUMBER(10) PRIMARY KEY, sectiontemplate BLOB, sectionname VARCHAR2(255), sectioncomment VARCHAR2(255), sectioninfo NUMBER(10))");

sidcounter = 1;
stidcounter = 1;
authorinfoidcounter= 1; s.executeUpdate("insert into reportsection values(" + sidcounter + ", " + stidcounter + ", " + Integer.valueOf(textFieldn.getText()) + ", " + sdsstate + ", " + Integer.valueOf(textField11.getText()) + ")");

sectname = textField16.getText().toString(); try
{
con.setAutoCommit(false);

//new row
PreparedStatement pstmt = con.prepareStatement("insert into sectionlist values(" + stidcounter + ", EMPTY_BLOB(), '" + textField16.getText() + "', '" + textField19.getText() + "', " + authorinfoidcounter + ")");
pstmt.executeUpdate();

//lock new row
pstmt = con.prepareStatement("select sectiontemplate from sectionlist where sectiontemplateid = " + stidcounter + " for update");
pstmt.executeUpdate();

File file = new File(tdir + tfilename);
FileInputStream fis = new FileInputStream(file);
pstmt = con.prepareStatement("update sectionlist set sectiontemplate=? where sectiontemplateid=" + stidcounter);
//PreparedStatement pstmt = con.prepareStatement("insert into image (image) values (?)");
pstmt.setBinaryStream(1, fis, (int)file.length());
//pstmt.setString(2, dir + filename);
pstmt.executeUpdate();
pstmt.close();

fis.close();

}
catch (IOException ioe)
{
ioe.printStackTrace();

}

}
catch (SQLException sqle){.....}


thx in advance...;-)


Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: problem inserting blob in oracle database Posted: May 14, 2002 4:16 PM
Reply to this message Reply
Try to use the OCI-driver instead of the pure-Java driver. This should solve the problem !
Note that this worked on Win-NT client machine running NT4. I believe you are using Oracle 8i with Java 2 ?
Is your column the last one ?

Thomas SMETS,
SCJP2- Brussels

locutus

Posts: 6
Nickname: locutus
Registered: May, 2002

Re: problem inserting blob in oracle database Posted: May 15, 2002 12:11 AM
Reply to this message Reply
hi,
oracle8i and jaca 1.3_01 on linux.
no, the column is the second.

thx

Thomas SMETS

Posts: 307
Nickname: tsmets
Registered: Apr, 2002

Re: problem inserting blob in oracle database Posted: May 15, 2002 10:08 AM
Reply to this message Reply
Well Oracle love the varchar / varchar2 as last one
:-)
May be modifying that (making it last) should help unless you could insert DATA's like that earlier on with "normal" language (C, C++, python, ...) ?

Give some feed back,

Thomas SMETS,
SCJP2 - Brussels

locutus

Posts: 6
Nickname: locutus
Registered: May, 2002

Re: problem inserting blob in oracle database Posted: May 16, 2002 1:20 AM
Reply to this message Reply
thx for your help.
i have solved it by passing the data over java beans.
locutus

Flat View: This topic has 4 replies on 1 page
Topic: files Previous Topic   Next Topic Topic: the great puzzle of finalizing

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use