Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Reading CLOBs with JDBC

Re: Reading CLOBs with JDBC

From: Frederik Hansen <roirex_at_post1.tele.dk>
Date: Fri, 24 Sep 1999 09:10:54 +0200
Message-ID: <37EB23FE.AF391CD3@post1.tele.dk>


Hi Benjamin

> I've been trying to do CRUD (Create, Read, Update, Delete) functions
> with JDBC on table with a CLOB field. I've been able to successfully
> create rows, update and delete them, but when I try to populate a

No, you proberly haven't. I did it the same way as you do. By using bytes, but this is not the way. Not at all. (You can do a check and select the clob-field in a SQL-Plus. You should be able to read the field in clear-text, which you proberly are not. I wasn't)

You should do it in some way like this:

	ResultSet CLOBresl = jdbc.query("SELECT clob_field "+
		"FROM clobtable "+
		"WHERE id = 1");
			
	CLOBresl.next();
			
	java.io.OutputStream out;

	oracle.sql.CLOB cl =

((oracle.jdbc.driver.OracleResultSet)CLOBresl).getCLOB(1);                         

        out =
(oracle.jdbc.driver.OracleClobOutputStream)cl.getAsciiOutputStream();

	out.write(rating_model.pre_rate_script);
	out.flush();
	out.close();

This is both for UPDATE and INSERT, please notice the select, also when updating! (Ugly way to do it, I think)

So when you insert you do this:

"Insert to clobtable values (' ')"

And then you select the field, like in the code above..

Frederik Hansen Received on Fri Sep 24 1999 - 02:10:54 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US