× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Are you missing the

rs.beforeFirst();

after the dsply statement?

Gary

-----Original Message-----
From: java400-l-bounces@xxxxxxxxxxxx [mailto:java400-l-bounces@xxxxxxxxxxxx]
On Behalf Of James H. H. Lampert
Sent: Friday, July 05, 2013 5:02 PM
To: java400-l@xxxxxxxxxxxx
Subject: Running into a problem with JDBCR4 expansion

I've exposed the 2-parameter version of Connection.createStatement in the
JDBCR4 source as
D createStatement2...
D PR ExtProc(*JAVA:
D 'java.sql.Connection':
D 'createStatement')
D like(Statement)
D RSTYPE 10I 0 VALUE
D RSCONCUR 10I 0 VALUE

and then incorporated it in a new version of JDBC_ExecQry:
P JDBC_ExecQrySc B export
D JDBC_ExecQrySc PI like(ResultSet)
D conn like(Connection) const
D sql 32767A varying const options(*varsize)
D stmt s like(Statement)
D temp s like(ResultSet)
D rs s like(ResultSet)
/free
jdbc_begin_object_group(50);

monitor;
stmt = createStatement2( conn: 1005: 1007);
temp = executeQuery( stmt : s(sql));
jdbc_end_object_group(temp: rs);
on-error;
jdbc_end_object_group();
return *NULL;
endmon;

return rs;
/end-free
P E
(1005 is, at least according to the JavaDocs,
ResultSet.TYPE_SCROLL_SENSITIVE, and 1007 is ResultSet.CONCUR_READ_ONLY)

I've also exposed the previous(), first(), last(), beforeFirst(), and
afterLast() methods, and wrapped them in RPG, following the example of the
already extant JDBC_NextRow, e.g.:

D b4FirstRec...
D PR 1N ExtProc(*JAVA:
D 'java.sql.ResultSet':
D 'beforeFirst')
. . .
P JDBC_B41stRow B export
D JDBC_B41stRow PI 1N
D rs like(ResultSet)
/free
monitor;
return B4FirstRec(rs);
on-error;
return *OFF;
endmon;
/end-free
P E


But while this Java fragment works perfectly (accessing my test MySQL
server), displaying the example database records twice:
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last"); //Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last); } rs.beforeFirst();
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}

this RPGLE fragment only goes through the selected records once, and
displays '0' (*OFF, false) as the value of jdbc_b41stRow(rs):
rs = jdbc_ExecQrySc( conn : 'Select CUNMBR,CUNAME'
+ ' from AQUESTVIEW/VIEWCUS'
+ ' where CUNMBR > 700000'
);
dow (jdbc_nextRow(rs));
CUSNUM = %int(jdbc_getCol(rs: 1));
NAME = jdbc_getCol(rs: 2);
except LINE;
enddo;
dsply jdbc_b41stRow(rs);
dow (jdbc_nextRow(rs));
CUSNUM = %int(jdbc_getCol(rs: 1));
NAME = jdbc_getCol(rs: 2);
except LINE;
enddo;

Anybody have a clue what I could be doing wrong?

--
JHHL
--


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.