About resultset

i want to transfer the resulset to a different array.how can i do that.shall i use vector or arraylist.or is there an easier way.could you give me sample codes.

Iterate through the ResultSet, create objects representing the rows, and add those objects to a Collection of your choice. ArrayList is the most common general-purpose collection.

Similar Messages

  • A question about ResultSet.UpdateObject(int column, Object x)

    hi, I write some code which use the TableModel to represent the data fetched from MS-ACCESS.
    the problem is about the UpdateObject(...) method which is in the implement of the AbstractTableModel method setAtValue(). when transfered OBJECT TYPE is java.lang.String, I can't get the correct result in the JTable view.
    my code is as below, could somebody point me out my problem
    public class MyTableModel extends AbstractTableModel {
        private ResultSet rs ;
        private ResultSetMetaData rsmd;
        /** Creates a new instance of MyTableModel */
        public MyTableModel() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            String url = "jdbc:odbc:CoffeeBreak";
            try {
                Connection con = DriverManager.getConnection(url,"","");
                String strSQL = "SELECT * FROM COFFEES";
                Statement pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                rs = pSt.executeQuery(strSQL);
                rsmd = rs.getMetaData();
            } catch (SQLException ex) {
                ex.printStackTrace();
    /* table model retrieve the Class type of a column method here*/
    public Class getColumnClass(int c){
            try {
                return Class.forName(rsmd.getColumnClassName(c+1));
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return String.class;
    //method of update database and JTable after user edited a table cell
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            try {
                int concurrency = rs.getConcurrency();
                if(concurrency == 1008){
                    rs.absolute(rowIndex+1);    //the JTable row index is start from 0,so plus 1
                    rs.updateObject(columnIndex+1, aValue);//the JTable column index is start from 0, so plus 1
                    rs.updateRow();
            } catch (SQLException ex) {
                ex.printStackTrace();
        }when the column type is about java.lang.String, the cell's result is incorrect, it looks like "[B@1f8f72f" and database can't update.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    It's me again.
    I post the whole class code here
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.AbstractTableModel;
    * @author qhj
    public class MyTableModel extends AbstractTableModel {
        /** Creates a new instance of MyTableModel */
        private ResultSet rs ;
        private ResultSetMetaData rsmd;
        private Statement pSt;
        private String strSQL;
        public MyTableModel() {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            String url = "jdbc:odbc:CoffeeBreak";
            try {
                Connection con = DriverManager.getConnection(url,"","");
                strSQL = "SELECT * FROM COFFEES";
                pSt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
                rs = pSt.executeQuery(strSQL);
                rsmd = rs.getMetaData();
            } catch (SQLException ex) {
                ex.printStackTrace();
        public int getRowCount() {
            try {
                rs.last();
                return rs.getRow();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return 0;
        public int getColumnCount() {
            try {
                return rsmd.getColumnCount();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return 0;
        public Object getValueAt(int rowIndex, int columnIndex) {
            try {
                rs.absolute(rowIndex+1);
                return rs.getObject(columnIndex+1);
            } catch (SQLException ex) {
                ex.printStackTrace();
            return null;
        public String getColumnName(int column){
            try {
                return rsmd.getColumnName(column+1);
            } catch (SQLException ex) {
                ex.printStackTrace();
            return "N/A";
        public Class getColumnClass(int c){
            try {
                return Class.forName(rsmd.getColumnClassName(c+1));
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } catch (SQLException ex) {
                ex.printStackTrace();
            return String.class;
        public boolean isCellEditable(int row, int col) {
            //Note that the data/cell address is constant,
            //no matter where the cell appears onscreen.
            return true;
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
            try {
                int concurrency = rs.getConcurrency();
                if(concurrency == 1008){
                    rs.absolute(rowIndex+1);
                    rs.updateObject(columnIndex+1, aValue);
                    //rs.updateRow();
                    //rs = pSt.executeQuery(strSQL);
            } catch (SQLException ex) {
                ex.printStackTrace();
            fireTableDataChanged();
    }

  • Question about resultset

    Hi,
    I have a simple problem. I wish to move data from a resultset to a string[]. However, I do not know the number of rows in the resultset.
    I have tried something like this:
    while (resultset.next()) {
                while ( (sqlData[rowCount++] = resultset.getString(++colCount))){}
                           colCount = 0;
    }Javac said it expected a boolean and not a string. Well of course it requiers a boolean, but isn't a boolean returned if the operation on the resultset isn't possible?
    All help appriciated...
    Karl XII

    It is possible to retrieve the number of rows from a resultset --
    Statement stmt= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READONLY);
    ResultSet rs= stmt.executeQuery("<your select query here>");
    int totalRows;
    if (rs.last()) // can it move to the last row?
       totalRows= rs.getRow(); // get its row number
    else
       totalRows= 0; // no rows in the resultset
    rs.first() // set the cursor back to the startNote that the resultset has to be scrollable (TYPE_SCROLL_INSENSITIVE).
    kind regards,
    Jos

  • A question about ResultSet

    Does anyone can tell me how to use ResultSet.getDate(String field, Calendar cal)method,, I have tried many way,,, but if I use this method, everytime throw a AbstractMethodError... thanks

    Calendar calendar = Calendar.getInstance();
    while(rs.next){
    rs.getDate("SYSDATE", calendar);
    and SYSDATE is a kind of DATE
    java.lang.AbstractMethodError occur while I run
    rs.getDate() Method ..
    is this a bug of java???It may simply be that the driver you are using doesn't support this method. Which driver and version are you using?
    Col

  • Question about ResultSet Columns

    Do resultset columns start at index 0 or 1???

    From the [url http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html]API docs
    The ResultSet interface provides getter methods (getBoolean, getLong, and so on) for retrieving column values from the current row. Values can be retrieved using either the index number of the column or the name of the column. In general, using the column index will be more efficient. Columns are numbered from 1. For maximum portability, result set columns within each row should be read in left-to-right order, and each column should be read only once.

  • 2 Questions about ResultSet

    Q1. Do I need to ( Or should I for good programming practice ) explicitly close a ResultSet ?
    Q2. Does a ResultSet contain retrieved records from the query or a list of "pointers" to records which are retrieved from the DB only as the ResultSet is walked through?
    Thanks ..... J

    Q1. Do I need to ( Or should I for good programming
    practice ) explicitly close a ResultSet ?You should, and sometimes you need to, e.g. to avoid getting a "too many open cursors" database error when using lots of ResultSets within a short span of time.
    Q2. Does a ResultSet contain retrieved records from
    the query or a list of "pointers" to records which
    are retrieved from the DB only as the ResultSet is
    walked through?Depends on the implementation. Typically, it does contain some (if not all) records. Other data (e.g. BLOBs) might be read in streaming mode.

  • About ResultSet.getDate

    when I insert the table ,I use the to_date function to insert the date value,such as to_date('2003-05-24 14:00:00','yyyy-mm-dd hh24;mi:ss')
    when using the Result.getDate,the return value of date is "2003-05-24",how can I get the correct value ?
    thks very much!!!!!!!!!!!!!!!

    try getTimestamp() instead.

  • Should columns only be read once....

    Good day,
    I have a question about reading the resultset.
    I was recently reading the java.sql API.
    And in the description for the Resultset interface.
    It mentions that "each column should be read only once"     
    Currently I don't call columns via results.getString("column") directly.
    I usually set it to a variable and the use the variable as much as i need.
    This method mainly helps me keep organized.
    I was wondering if there are any real problems or issues that may arise from calling a column directly a numerous amount of times.
    I don't plan on chaning my current method of going about resultsets, but i was just curious.
    thanks,
    alex

    Hi,
    You can scroll through the result set and read a column any number of time (provided proper resultSetType is set during statement creation).
    see the scenario where such things will not work (but depends on the driver implementation). suppose u are retrieving rows in bulk (say >10k number of rows of large size).retrieving the bulk will give u out of memory etc exceptions. and if u set the fetchsize(int size)method things will become ok. but here u cant gurantee that u will get the column value on ur second visit to the same column (ie calling rs.getXX()method second time) .
    so the rule thumb is retrieve the column value only once and store it in a variable- this is what u are doing rt now (if its a large value, process it on the spot according to ur need)
    HTH,
    -asharafkk

  • Retrieving records at a single fetch !!!

    Hi All. there is a big qns in my mind. Let me explain the problem first. I want to retrieve some 1000 records from the database but want to show 10 records per page. while clicking next or somthing the 2nd page i want show 10 records. Is this case, the transaction goes to the database and come back with the required records. For every time database interation is there and takes some time. If i want to fetch all the 1000 records in a single fetch and show it 10 by 10 means how to do that. Where i've to store the fetched records ? Could anyone please provide me a good solution for this. If possible with some sample codes too. Thankx in Advance.
    Siva

    Hi,
    Thanks for ur response. In the case of
    ase of retrieving all the records from the database
    which i don't know how many records(no of rows and
    cols not known) are in the table. How to proceed with
    this? And one imp thing, after fetching this many
    records where this gets stored? Awaiting for ur reply.The ArrayList rows will contain one entry per row retrieved from the database. Each entry in rows will be an ArrayList as well, where each element is the content of the respective column from your query.
    The ArrayList rows will grow dynamically. The number specified in the constructor is only the initial size. Read up the docs for ArrayList.
    The number of columns can be retrieved from the ResultSetMetaData object. Read the documentation about ResultSet and ResultSetMetaData
    When displaying this page by page, you just need to iterate over rows and display the approriate number of entries from there.
    Thomas

  • Getting error "outside VM" when using updateRow();

    Hi guys,
    I've been posting alot about resultset problems lately, but I can't seam to get the hang of it. But I guess that will come in time.
    This time it seams like i've really manage to mess things up. Im getting an error "outside the VM", check the snippet at the end of the message. First take a look at my code; I'm trying to update a ResultSet with values from a TableModel:
    try{
                for(int i =1; i <= aModel.getRowCount(); i++) {
                        rs.absolute(i);                   
                        Vector modelData = aModel.getDataVector();                                    
                        int modelValue = Integer.parseInt((
                                                (Vector)modelData.elementAt(i-1)).elementAt(4).toString());                  
                        Integer currentInteger = new Integer(modelValue);
                        rs.updateString("Artnamn", (((Vector)modelData.elementAt(i-1)).elementAt(1)).toString() );
                        rs.updateString("Utpris", (((Vector)modelData.elementAt(i-1)).elementAt(2)).toString() );
                        rs.updateString("Info", (((Vector)modelData.elementAt(i-1)).elementAt(3)).toString() );
                        rs.updateString("Ilager", currentInteger.toString() ); 
                        rs.updateRow();
                        theGui.setStatus("Lagerstatus Sparade");
            } catch(SQLException e) {
                System.out.println("Uppdateraknappen:" + e);
            }And here is the error im getting. I occors when i do rs.updateRow();
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D261419
    Function=Java_sun_jdbc_odbc_JdbcOdbc_bindColBinary+0x112
    Library=C:\j2sdk1.4.1_02\jre\bin\JdbcOdbc.dll
    Current Java thread:
         at sun.jdbc.odbc.JdbcOdbc.bindColBinary(Native Method)
         at sun.jdbc.odbc.JdbcOdbc.SQLBindColBinary(JdbcOdbc.java:238)
         at sun.jdbc.odbc.JdbcOdbcResultSet.bindBinaryCol(JdbcOdbcResultSet.java:5017)
         at sun.jdbc.odbc.JdbcOdbcResultSet.bindCol(JdbcOdbcResultSet.java:4761)
         at sun.jdbc.odbc.JdbcOdbcResultSet.updateRow(JdbcOdbcResultSet.java:4074)
         at LagerPanel.uppdateraKnappActionPerformed(LagerPanel.java:107)
         at LagerPanel.access$000(LagerPanel.java:17)
         at LagerPanel$1.actionPerformed(LagerPanel.java:75)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
         at java.awt.Component.processMouseEvent(Component.java:5134)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Dynamic libraries:
    0x00400000 - 0x00406000      C:\j2sdk1.4.1_02\bin\java.exe
    0x77F50000 - 0x77FF9000      C:\WINDOWS\System32\ntdll.dll
    0x77E60000 - 0x77F4A000      C:\WINDOWS\system32\kernel32.dll
    0x77DC0000 - 0x77E5D000      C:\WINDOWS\system32\ADVAPI32.dll
    0x78000000 - 0x78086000      C:\WINDOWS\system32\RPCRT4.dll
    0x77C00000 - 0x77C53000      C:\WINDOWS\system32\MSVCRT.dll
    0x6D340000 - 0x6D46A000      C:\j2sdk1.4.1_02\jre\bin\client\jvm.dll
    0x77D30000 - 0x77DBC000      C:\WINDOWS\system32\USER32.dll
    0x77C60000 - 0x77CA0000      C:\WINDOWS\system32\GDI32.dll
    0x76B30000 - 0x76B5D000      C:\WINDOWS\System32\WINMM.dll
    0x6D1E0000 - 0x6D1E7000      C:\j2sdk1.4.1_02\jre\bin\hpi.dll
    0x6D310000 - 0x6D31E000      C:\j2sdk1.4.1_02\jre\bin\verify.dll
    0x6D220000 - 0x6D239000      C:\j2sdk1.4.1_02\jre\bin\java.dll
    0x6D330000 - 0x6D33D000      C:\j2sdk1.4.1_02\jre\bin\zip.dll
    0x6D270000 - 0x6D28C000      C:\j2sdk1.4.1_02\jre\bin\jdwp.dll
    0x6D180000 - 0x6D185000      C:\j2sdk1.4.1_02\jre\bin\dt_socket.dll
    0x71AA0000 - 0x71AB4000      C:\WINDOWS\System32\ws2_32.dll
    0x71A90000 - 0x71A98000      C:\WINDOWS\System32\WS2HELP.dll
    0x55600000 - 0x5561D000      C:\Program\Microsoft Firewall Client\wspwsp.dll
    0x76D50000 - 0x76D66000      C:\WINDOWS\System32\iphlpapi.dll
    0x71A40000 - 0x71A7C000      C:\WINDOWS\System32\mswsock.dll
    0x76F10000 - 0x76F35000      C:\WINDOWS\System32\DNSAPI.dll
    0x76FA0000 - 0x76FA7000      C:\WINDOWS\System32\winrnr.dll
    0x76F50000 - 0x76F7D000      C:\WINDOWS\system32\WLDAP32.dll
    0x71A80000 - 0x71A88000      C:\WINDOWS\System32\wshtcpip.dll
    0x76FB0000 - 0x76FB5000      C:\WINDOWS\System32\rasadhlp.dll
    0x6D000000 - 0x6D105000      C:\j2sdk1.4.1_02\jre\bin\awt.dll
    0x72FD0000 - 0x72FF3000      C:\WINDOWS\System32\WINSPOOL.DRV
    0x76370000 - 0x7638C000      C:\WINDOWS\System32\IMM32.dll
    0x7CCC0000 - 0x7CDE1000      C:\WINDOWS\system32\ole32.dll
    0x6D190000 - 0x6D1E0000      C:\j2sdk1.4.1_02\jre\bin\fontmanager.dll
    0x51000000 - 0x51047000      C:\WINDOWS\System32\ddraw.dll
    0x73B90000 - 0x73B96000      C:\WINDOWS\System32\DCIMAN32.dll
    0x5C000000 - 0x5C0C8000      C:\WINDOWS\System32\D3DIM700.DLL
    0x746F0000 - 0x74734000      C:\WINDOWS\System32\MSCTF.dll
    0x63000000 - 0x63014000      C:\WINDOWS\System32\SynTPFcs.dll
    0x77BF0000 - 0x77BF7000      C:\WINDOWS\system32\VERSION.dll
    0x6D260000 - 0x6D26B000      C:\j2sdk1.4.1_02\jre\bin\JdbcOdbc.dll
    0x15440000 - 0x15472000      C:\WINDOWS\System32\ODBC32.dll
    0x77330000 - 0x773BB000      C:\WINDOWS\system32\COMCTL32.dll
    0x773C0000 - 0x77BB4000      C:\WINDOWS\system32\SHELL32.dll
    0x70A70000 - 0x70AD5000      C:\WINDOWS\system32\SHLWAPI.dll
    0x76390000 - 0x763D5000      C:\WINDOWS\system32\comdlg32.dll
    0x78090000 - 0x78174000      C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.10.0_x-ww_f7fb5805\comctl32.dll
    0x1F850000 - 0x1F867000      C:\WINDOWS\System32\odbcint.dll
    0x155A0000 - 0x155FE000      C:\WINDOWS\System32\SQLSRV32.dll
    0x5C6B0000 - 0x5C6DD000      C:\WINDOWS\System32\SQLUNIRL.dll
    0x77110000 - 0x7719B000      C:\WINDOWS\system32\OLEAUT32.dll
    0x71C10000 - 0x71C5E000      C:\WINDOWS\System32\NETAPI32.dll
    0x75920000 - 0x75927000      C:\WINDOWS\System32\NDDEAPI.DLL
    0x1FA20000 - 0x1FA37000      C:\WINDOWS\System32\sqlsrv32.rll
    0x76F80000 - 0x76F90000      C:\WINDOWS\System32\Secur32.dll
    0x15600000 - 0x15619000      C:\WINDOWS\System32\odbccp32.dll
    0x15620000 - 0x1562F000      C:\WINDOWS\System32\DBNETLIB.DLL
    0x71AC0000 - 0x71AC9000      C:\WINDOWS\System32\WSOCK32.dll
    0x71F70000 - 0x71F74000      C:\WINDOWS\System32\security.dll
    0x76D00000 - 0x76D1D000      C:\WINDOWS\system32\msv1_0.dll
    0x76790000 - 0x767A3000      C:\WINDOWS\System32\ntdsapi.dll
    0x762A0000 - 0x76329000      C:\WINDOWS\system32\crypt32.dll
    0x76280000 - 0x7628F000      C:\WINDOWS\system32\MSASN1.dll
    0x15820000 - 0x15844000      D:\Program\Trillian\events.dll
    0x76C80000 - 0x76CA2000      C:\WINDOWS\system32\imagehlp.dll
    0x6DAA0000 - 0x6DB1D000      C:\WINDOWS\system32\DBGHELP.dll
    0x76BE0000 - 0x76BEB000      C:\WINDOWS\System32\PSAPI.DLL
    Local Time = Wed Jan 14 15:03:28 2004
    Elapsed Time = 140
    # The exception above was detected in native code outside the VM
    # Java VM: Java HotSpot(TM) Client VM (1.4.1_02-b06 mixed mode)
    #All help will be greatly appriciated!
    - Karl XII

    Here is the code that creates the resultSet:
    ResultSet resultset = null;
            try {
            Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
             Connection connection2= DriverManager.getConnection(
                   "jdbc:odbc:mittDSNnamn", "", ""); //Pass och userID*/
             Statement stmt = connection2.createStatement(
                                          ResultSet.TYPE_SCROLL_INSENSITIVE,
                                          ResultSet.CONCUR_UPDATABLE);
             resultset = stmt.executeQuery(sqlCommand); 
          } catch (Exception e) {
             System.out.println( "I sqlHanteraren f�r vi: " + e);  

  • Using CallableStatement.wasNull() after getObject()

    In our aplpication we are returning ResultSets from PL/SQL functions. We use CallableStatement.getObject()
    to return the ResultSet. After calling getObject we call wasNull() to make sure
    we did receive something.
    Originally we were using the jcbd thin driver provided by Oracle and our code
    ran fine. We had problems with that driver and switched to the OCI driver. The
    OCI driver does not like our code calling wasNull after getObject(). It throws
    and exception saying we have not called a getXXX method yet.
    The specification is kind of vague on this, it says wasNull can be called after
    any getXXX method. My question is, is there a problem with the OCI driver or
    is or code wrong?
    Below is a snippet of code that worked with the thin driver but not with the OCI
    driver:
    CallableStatement _stmt = null;
              int _arg = 1;
              try {
                   stmt = connection.prepareCall(GET_OTHER_PERFORMANCE_ASSETS_STMT);
                   stmt.registerOutParameter(arg++, sonymusic.util.JDBCHelper.SONYMUSIC_CURSOR);
                   if (inSiteId == null) {
                        stmt.setNull(arg++, java.sql.Types.BIGINT);
                   } else {
                        stmt.setLong(arg++, inSiteId.longValue());
                   if (inPerformanceId == null) {
                        stmt.setNull(arg++, java.sql.Types.BIGINT);
                   } else {
                        stmt.setLong(arg++, inPerformanceId.longValue());
                   if (authUserIdIn == null) {
                        stmt.setNull(arg++, java.sql.Types.BIGINT);
                   } else {
                        stmt.setLong(arg++, authUserIdIn.longValue());
                   _stmt.execute();
                   java.sql.ResultSet result = (java.sql.ResultSet)stmt.getObject(1);
                   if (_stmt.wasNull())
                        return null;
                   else
                        return _result;

    Hi Jeff,
    as mentioned in the spec, refereing to the doc you refered to earlier:
    You should be able to get the resultset first and then read the param on the
    resultset and then make a call to CallableStatement.wasNull to discover if
    the read returned a SQL "NULL". (if this value read from the resultset is a
    SQL "NULL" the wasNull() call will return a true).
    Hope this answers your questions here and clears up any confusion with the
    java null and, the SQL NULL that the wasNull call detects.
    getObject() is basically returning you what you asked it to return when you
    registered the out parameter.
    http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html
    7.3.2 Retrieving NULL values as OUT parameters
    As with ResultSets, in order to determine if a given OUT parameter value is
    SQL "NULL" you must first read the parameter and then use the
    CallableStatement.wasNull method to discover if the read returned a SQL
    "NULL".
    When you read a SQL "NULL" value using one of the CallableStatement.getXXX
    methods, you will receive a value of null, zero, or false, following the
    same rules specified in section 7.1.2 for the ResultSet.getXXX methods.
    sree
    "J Drost" <[email protected]> wrote in message
    news:[email protected]...
    >
    I am comfortable with a getXXX on available returning an empty result setif the
    pl/sql function itself returned an empty result set (if you do 'where 1 =0');
    Just as I am comfortable with a getInt invocation returning a 0 if thepl/sql
    function itself returned a 0. Or Course.
    I do however expect to be able to check wasNull on the CallableStatementafter
    getting a ResultSet from an out parameter. If the pl/sql function itselfdid
    not return a result set (it is possible in Oracle to simply not return avalue
    from a function), then I expect wasNull to return true.
    I would imaging that it is open to discussion what the getXXX shouldreturn if
    the database doesn't return anything. I would expect a null (after all Iam calling
    getObject, and you wouldn't expect the driver any other kind of emptyobject,
    so why an empty result set) but you could argue that an empty result setwould
    be acceptable. Regardless of that argument; if a function didn't returnthe result
    set, after the getXXX the wasNull should return true. Otherwise thedriver is
    hiding the actual results of the database call.
    Jeff
    "Sree Bodapati" <[email protected]> wrote:
    And I would like to add this note from 'Joe' here :
    "an empty result set is still a result set, not a null.
    Applications may well run queries that return no rows, but the
    application
    may still want the result set metadata, which is only available from
    the resultset. In fact some applications purposely execute queries
    with a clause like 'where 1 = 0' to ensure no rows are returned, but
    guarantee that they get the metadata."
    "Sree Bodapati" <[email protected]> wrote in message
    news:[email protected]...
    If you read through the same doc an little furture, They talk about
    resultsets,
    7.3.2 Retrieving NULL values as OUT parameters
    As with ResultSets, in order to determine if a given OUT parametervalue
    is
    SQL "NULL" you must first read the parameter and then use the
    CallableStatement.wasNull method to discover if the read returned aSQL
    "NULL".
    When you read a SQL "NULL" value using one of the
    CallableStatement.getXXX
    methods, you will receive a value of null, zero, or false, followingthe
    same rules specified in section 7.1.2 for the ResultSet.getXXX methods.
    hth
    sree
    "J Drost" <[email protected]> wrote in message
    news:[email protected]...
    Is their any explanation as to why a default value (an empty result
    set)
    is returned
    without setting the wasNull flag? This behavior seems to be
    inconsistent
    with
    the way other out parameters work. For example, when a function
    that is
    expected
    to return a number doesn't return a value, the default value (zero)
    is
    returned
    from the CallableStatement.getInt() method, but the wasNull flag
    is set
    to
    true.
    I don't know, it just doesn't seem consistent to me.
    Also, you are saying that if I have a pl/sql function that returns
    a
    REFCURSOR
    (a weakly typed cursor), and that function doesn't return a value,
    then
    the driver
    is going to create a ResultSet for me that contains no rows and has
    a
    ResultSetMetaData
    with a columnCount of zero? I would expect to get a java null based
    on
    what the
    spec, as well as they way other parameter types work.
    http://java.sun.com/j2se/1.3/docs/guide/jdbc/spec/jdbc-spec.frame7.html
    7.1.2 Null result values
    * A Java "null" value for those getXXX methods that return Javaobjects.
    * A zero value for getByte, getShort, getInt, getLong, getFloat,and
    getDouble
    * A false value for getBoolean.
    "Sree Bodapati" <[email protected]> wrote:
    wasNull() checks to see if the last OUT param value is SQL NULL.
    if
    you
    have a CURSOR (ResultSet equivalent) as the OUT param then it willnot
    be
    SQL NULL if no results are returned.
    The Weblogic oci driver returns an empty resultset object in sucha
    case.
    I
    dont think it sets the wasNull() to return true in such a scenario.
    HTH
    Sree
    "Robert DeWilder" <robert@[email protected]> wrote in message
    news:[email protected]...
    In our aplpication we are returning ResultSets from PL/SQL
    functions.
    We
    use CallableStatement.getObject()
    to return the ResultSet. After calling getObject we call
    wasNull()
    to
    make sure
    we did receive something.
    Originally we were using the jcbd thin driver provided by Oracle
    and
    our
    code
    ran fine. We had problems with that driver and switched to the
    OCI
    driver. The
    OCI driver does not like our code calling wasNull after
    getObject().
    It
    throws
    and exception saying we have not called a getXXX method yet.
    The specification is kind of vague on this, it says wasNull can
    be
    called
    after
    any getXXX method. My question is, is there a problem with the
    OCI
    driver
    or
    is or code wrong?
    Below is a snippet of code that worked with the thin driver but
    not
    with
    the OCI
    driver:
    CallableStatement _stmt = null;
    int _arg = 1;
    try {
    _stmt =
    connection.prepareCall(GETOTHER_PERFORMANCE_ASSETS_STMT);
    stmt.registerOutParameter(arg++,sonymusic.util.JDBCHelper.SONYMUSIC_CURSOR);
    if (inSiteId == null) {
    stmt.setNull(arg++, java.sql.Types.BIGINT);
    } else {
    stmt.setLong(arg++, inSiteId.longValue());
    if (inPerformanceId == null) {
    stmt.setNull(arg++, java.sql.Types.BIGINT);
    } else {
    stmt.setLong(arg++, inPerformanceId.longValue());
    if (authUserIdIn == null) {
    stmt.setNull(arg++, java.sql.Types.BIGINT);
    } else {
    stmt.setLong(arg++, authUserIdIn.longValue());
    _stmt.execute();
    java.sql.ResultSet _result =
    (java.sql.ResultSet)_stmt.getObject(1);
    if (_stmt.wasNull())
    return null;
    else
    return _result;

  • Unclear about closing ResultSets

    Please provide clarification: The JavaDoc for ResultSets says that you don't have to explicitly close ResultSet objects since the RS will be closed when its defining Statement is closed or when the RS is garbage collected.
    The Oracle JDBC Developer's Guide and Reference states (in the section titled "Closing the Result Set and Statement Objects"):
    "You must explicitly close the ResultSet and Statement objects after you finish using them. This applies to all
    ResultSet and Statement objects you create when using the Oracle JDBC drivers. The drivers do not have
    finalizer methods; cleanup routines are performed by the close() method of the ResultSet and Statement
    classes. If you do not explicitly close your ResultSet and Statement objects, serious memory leaks could
    occur. You could also run out of cursors in the database."
    So, does the Oracle driver operate differently than the JDBC standard in this regard?

    The JavaDoc for ResultSets says that you don't have to explicitly close ResultSet objects since the RS will be closed when its defining Statement is closed or when the RS is garbage collected.In Oracle JDBC, if you close the statement, then the result set is also closed, unless you obtained the result set as an OUT parameter from a stored procedure or function that returns a REF CURSOR.
    However, it is definitely not prudent to wait until the result set is garbage collected, since you have no explicit control over that! Depending on your database setup, you'll typically be able to open a couple dozen statements before you start running out of database cursors.
    This is even more important if you are using SQLJ: there statements are automatically managed for you, so you'll never have to worry about closing them. However, if you do not close result sets (called iterators in SQLJ), the associated statement will be kept around and stays open (again, it might be garbage collected or it might not - no guarantees).

  • MDM iView resultset problem and question about eventing

    Hi experts,
    I created a MDM iView resultset for my main table as search table (comparison is not supported). When I click on preview I get an empty table ("Found <Tablename>: 0 of 10", table contains 10 entries at the moment). I tried the same with a subtable and everything works fine (all entries have been in the preview table). Any ideas why I don't get a result?
    My 2nd question: can I choose the parameter name in eventing (EPCF) on my own? So if I have Vendor_Id as field can I use vendorid as parameter name? Do I have to define anything in the listener iView (e.g. in detail iView for an event from resultset iView)? Maybe you have a useful tutorial link (please not SAP help section)?
    Thanks for your answers.
    Regards, bd

    It is possible to retrieve the number of rows from a resultset --
    Statement stmt= con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READONLY);
    ResultSet rs= stmt.executeQuery("<your select query here>");
    int totalRows;
    if (rs.last()) // can it move to the last row?
       totalRows= rs.getRow(); // get its row number
    else
       totalRows= 0; // no rows in the resultset
    rs.first() // set the cursor back to the startNote that the resultset has to be scrollable (TYPE_SCROLL_INSENSITIVE).
    kind regards,
    Jos

  • Want to know about the resultset closed exception

    hi,
    in my java programming, i have used two resultset objects.also two statement object have used.
    but the first resultset object is closed immediately after the second resultset object was created.
    then i have to use two resultset objects for my coding.
    what can i do?
    plzsnd me reply.

    You cannot have two result set simultaneously because you have only one cursor.
    To resolve this, you could store the data into a collection (a list form example) from the first result set that you close it. Then you open the second one and do your tasks using the collection.
    I think your problem could be resolved using PLSQL,
    hth

  • Question about updateRow in ResultSet

    Simple problem. When I update the values in a resultset with:
    rs.updateString("columnName", aString);
    rs.updateRow();the value of columnName is updated, but the values of all the other columns in the row are set to nothing. How do I prevent this from happening? Do I have to update all the column values when using updateRow, i.e getting the values from the resultset and then updating with the same values?
    - Karl XII

    Hi Karl,
    You could try using the following code:
    int numRows = 0;
    int empId = 1223;
    String updateEmp="update employees set department=?
    where id = ?";
    PreparedStatement pstmt =
    conn.prepareStatement(updateEmp);
    pstmt.setString(1,"department");
    pstmt.setInt(2,empId);
    numRows = pstmt.executeUpdate();
    pstmt.close();
    This piece of code would only update the columns that
    you mention in the PreparedStatement SQL query.
    Thanks,
    Rashmi.Thanx. But I have a resultSet that is linked to the database. I to only like to edit the value of a specific column in the resultset... any other suggestions?

Maybe you are looking for

  • AIR application crashes at certain point in windows vista

    Hi Dudes, I am facing a problem in Window vista. It always crash when we open the window component using Adobe AIR. I am creating the Dynamic window and adding the child component as window.rawChildren.addChild(object) like this.. we made the setup ,

  • How to output binary data to VISA

    i am interfacing labview with pic microcontroller through serial port using VISA. it is a stream of digital data which is being tranmitted ,stored in microcontroller and then retransmiited by microcontroller to other device...problem is when that dat

  • Document could not be opened

    I am getting an error message "Document could not be opened" on the Numbers app - What is the best way to recover the document? Will the folks in the Genius Bar in the local Apple shop be able to help?

  • Map Filename to field within mapping

    I have a requirement to map the filename to a field in the header of a file to file scenario and then create a new filename based upon the fields of the data structure of the header record. I am comfortable using the variable substituion to either ma

  • Item Recipe

    We are implementing oracle inventory r12 in cement industry. Is this scenario possible in inventory? Different raw materials are extracted and mixed together to make one that is clinker. A+B+C=D