This content has been marked as final. Show 4 replies
My question is, is there any way I can pull the data row by row instead of doing each data item one by one per column, and then just use println to print out each row?
A ResultSet gives you data 'row by row'. Each row is an array of columns. What you do with that array is up to you but no, there is no 'print' that will print the array of columns for a row.
The closest you can come is to define a SQL type with a structure that maps to the table row and then query the data as instances of that type.
See page 13-13 in the JDBC Dev Guide.
Retrieving SQLData Objects from a Callable Statement OUT Parameter
Consider you have an OracleCallableStatement instance, ocs, that calls a
PL/SQL function GETEMPLOYEE. The program passes an employee number to the
function. The function returns the corresponding Employee object.
Sample type and query to load it
That query returns one instance of the type for each row. Each instance has attributes for each column. You could then use the code like the sample from the JDBC doc to do what you wanted with the individual pieces. But there is still no way to 'print' it all at once.
-- type to match emp record create or replace type emp_scalar_type as object (EMPNO NUMBER(4) , ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2) ) / -- query that creates an instance of emp_scalar_type for each row SELECT emp_scalar_type( empno, ename, job, mgr, hiredate, sal, comm, deptno ) FROM emp;
You can 'un-relationalize' the row at the DBMS, by doing the SQL query, telling the DBMS to convert each column value to a string and to concatenate them into one string to return.
"select mycol1 + ", " + mycol2 + ", " + mycol3 from myTable"
that should return a result set with one row per table row, but with one column
that you would get via rs.getString(1), and would allow you to 'print the whole row'.