hi
this is how i update my CLOB containing xml in Oracle
String query = "SELECT C.paragraph from L4_ORT C WHERE C.uniqid = ? FOR
UPDATE";
PreparedStatement pstmt =
(OraclePreparedStatement)conn.prepareStatement(query);
pstmt.setAsciiStream((1,uniqid);
OracleResultSet rsCLOB =(OracleResultSet)pstmt.executeQuery();
rsCLOB.next();
CLOB para = rsCLOB.getCLOB(1);
// print initial length
System.out.println("CLOB LENGTH " + para.length());
// get clob writer
Writer clobWriter = para.getCharacterOutputStream();
// Open the sample file as a stream for insertion into the CLOB column
File xml = new File("C:/PDFProject/settings/myxml.xml");
FileReader fileReader = new FileReader(xml);
// Buffer to hold chunks of data to being written to the CLOB.
// In Oracle8.1.5 JDBC drivers a method getBufferSize() is available
// in the CLOB class that returns the optimal buffer size
char[] cbuffer = new char[10* 1024];
// Read a chunk of data from the sample file input stream, and write the
// chunk into the CLOB column output stream. Repeat till file has been
// fully read.
int nread = 0;
while ((nread= fileReader.read(cbuffer)) != -1) // Read from File
clobWriter.write(cbuffer,0,nread); // Write to CLOB
hope that helps..
.z
Tim Bond wrote:
> Take a look at the 8i App developer's guide for Large Objects & Java. Something
> like this might work . . . (although you are using CLOB type, not BLOB). It
> also might be that you are using a LONG type, not a CLOB type (don't use LONG!).
>
> -- Tim
>
> // Create a Statement:
> Statement stmt = conn.createStatement ();
> try
> {
> ResultSet rset = stmt.executeQuery (
> "SELECT sound FROM multimedia_tab WHERE clip_id = 1");
> if (rset.next())
> {
> // retrieve the LOB locator from the ResultSet
> BLOB sound_blob = ((OracleResultSet)rset).getBLOB (1);
> OraclePreparedStatement ops =
> (OraclePreparedStatement) conn.prepareStatement(
> "INSERT INTO multimedia_tab (clip_id, sound) VALUES (2, ?)");
> ops.setBlob(1, sound_blob);
> ops.execute();
> conn.commit();
> conn.close();
> }
> }
>
> Tim Yates wrote:
>
> > Hiya!
> >
> > My Entity beans (BMP) have to write XML data into a CLOB field in an oracle
> > database, but when I try to set it to a load of XML which is longer than
> > 4000 characters, I get the following exception:
> >
> > javax.ejb.EJBException: Error executing SQL INSERT INTO CONTENT (DOCUMENTID,
> > STARTDATE, ENDDATE, DEPARTMENT, TYPE, XML, SUBTYPE) VALUES ( ?, ?, ?, ?, ?,
> > ?): java.sql.SQLException: ORA-01461: can bind a LONG value only for insert
> > into a LONG column
> >
> > I am using classes12.zip for my drivers, and I am using the thin oracle
> > driver...
> >
> > Pleeeeease has anyone else hit upon this, and can they help? This is a
> > complete showstopper!! I cannot believe there is a 4000 char limit on CLOBS
> > in Oracle 8i, else why use them? I might as well use a varchar2...
> >
> > I think tonight is the night I painfully remove all my hair ;-)
> >
> > Tim...
> >
> > PS: I write my clobs like this (in the BMP bit of the entity bean)
> >
> > statement = connection.prepareStatement("INSERT INTO CONTENT
> > (DOCUMENTID, STARTDATE, ENDDATE, DEPARTMENT, TYPE, XML, SUBTYPE) VALUES (?,
> > ?, ?, ?, ?, ?, ?)");
> > statement.setString(1, documentid);
> > statement.setTimestamp(2, startdate);
> > statement.setTimestamp(3, enddate);
> > statement.setString(4, department);
> > statement.setString(5, type);
> > statement.setAsciiStream( 6, new ByteArrayInputStream(
> > xml.getBytes() ), xml.length() ) ;
> > statement.setString(7, subtype);
> > if (statement.executeUpdate() != 1)
> > {
> > throw new CreateException("Error adding row");
> > }
> >
> > with xml being a java.lang.String...
> >
> > --
> > --------------------------------------------------------------
> > To subscribe: [EMAIL PROTECTED]
> > To unsubscribe: [EMAIL PROTECTED]
> > List Help?: [EMAIL PROTECTED]
>
> --
> --------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> List Help?: [EMAIL PROTECTED]
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]