Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: WAS / Java / Cursors
Sam Jordan wrote:
> =
> Hi
> =
> I'm using Web application server 3.0.1 to access an Oracle 8 db
> (for Linux). Now I'd like to write programs in Java, which are
> started through the Java cartridge and which should access the db.
> =
> Problem: all sample programs seem to evaluate the number of rows
> first (select count(*)) before reading the data, to be able to
> provide arrays with sufficient size, and this seems to be inefficient.
> Is there no way to use a cursor concept in Java? Note, that I don't
> like to communicate between Java programs and PLSQL programs, since
> this would have to be done through ICX, which requires to use the
> Java native interface (JNI seems to be quite unusable in jdk 1.0.2).
> Therefore my preferred way to access Oracle data from Java is to
> call stored procedures, as done in the sample programs found in the
> WAS distribution.
> =
> Has anyone made experiences with the Java cartridge by accessing
> an Oracle DB? Some general hints about methods and strategies are
> very welcome.
> =
> bye
> --
> Sam Jordan
have you tried using prepared statements? =
try something like
CallableStatement cstmt;
ResultSet cursor;
=
// Use a PL/SQL block to open the cursor
cstmt = conn.prepareCall
("begin open ? for select name,age from data1; end;");
=
cstmt.registerOutParameter (1, OracleTypes.CURSOR);
cstmt.execute ();
cursor = ((OracleCallableStatement)cstmt).getCursor (1);
=
// Iterate through the result =
while (cursor.next ()){
String name = cursor.getString (1); int age = cursor.getInt (2); // do whatever ...
}
(-) Robert Krüger (-) SIGNAL 7 Gesellschaft für Informationstechnologie mbH (-) Brüder-Knauß-Str. 79 - 64285 Darmstadt, =
(-) Tel: 06151 665401, Fax: 06151 665373 (-) krueger_at_signal7.de, www.signal7.de Received on Sat Feb 20 1999 - 06:32:13 CST
![]() |
![]() |