Jdbc ResultSet.next() problem

this function is part of a class the extends AbstractTableModel
the line of code that is causing all the problems is right below lines that are indented all the way to the right and are in all caps
public void setAResultSet(ResultSet results)
try
ResultSetMetaData metadata =
results.getMetaData();
int columns = metadata.getColumnCount();
//now we know how many columns there are, so
//initialize the String array
columnNames = new String[columns];
//get the column names
for(int i = 0; i < columns; i++)
//remember - columns start with the indice at 1
columnNames[i] = metadata.getColumnLabel(i+1);
//get all the rows
dataRows = new Vector();
//will store the whole row of data
String[] oneRow;
while(results.next());
//re-allocate memory each time, b/c its a whole
//new row of data
oneRow = new String[columns];
//get the data in the current row, from every
//column
for(int i = 0; i < columns; i++)
{   System.err.println("Indice: " + i);
PROBLEM ON LINE BELOW
EXCEPTION STATES "INVALID CURSOR STATE"
oneRow[i] = results.getString(i+1);
//all of the data is collected, so store
dataRows.addElement(oneRow);
fireTableChanged(null);
catch(SQLException sqle)
System.err.println("Error in ResultsModel.setResultSet()");
System.err.println(sqle.getMessage());
Anyone has an idea as to why the SQLException is being thrown? Why is the cursor state invalid???

Hmmmm, try setting the cursor to the first row in the
result set just before you wish to get the data. That led to some interesting results. Here's what I added:
while(results.next());
//re-allocate memory each time, b/c its a whole
//new row of data
oneRow = new String[columns];
boolean texe = results.first();
THE REST IS THE SAME AS BEFORE
This also threw a SQLException, with the message: "Result set type is TYPE_FORWARD_ONLY"
That's very interesting b/c I know that its doing this from iteration 1. I know this because I have an err.println() message in the for loop that's nested in the while loop. That message, which tells me what i equals, did NOT show up. So, going to the first column somehow went backwards causing an error (but I've never had a problem using previous() or any other "backwards" methods for ResultSet objects before!). And where the cursor so going to first() is backwards? Whoever can figure this out deserves Duke Dollars.

Similar Messages

  • JDBC ResultSet.next() Error

    Can anyone help me with this error? I am running this in AIX box (java 1.3) using OCI to VMS RDB Server. I get this error when looping through the ResultSet.next().
    Thanks
    --Elie
    Exception in thread "main" java.sql.SQLException: ORA-09100: Message 9100 not found; No message file for product=NATCONN, facility=GTW
    %SYSTEM-F-NOMSG, Message number 0000C1C4
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java(Compiled Code))
    at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java(Compiled Code))
    at oracle.jdbc.oci8.OCIDBAccess.fetch(OCIDBAccess.java(Compiled Code))
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java(Compiled Code))
    at mbr.main(mbr.java(Compiled Code))

    I got it resolved by using NVL function on each of my DATE columns. I found a log from the RDB server complaining about dates. The NVL seems did the trick.
    Thanks again for your reply.
    --Elie                                                                                                                                                                                                                                                                                                                                                                                                           

  • ResultSet.next() and resultset.islast() problem

    I have query which returns 10 records. I run the using preparedStatement. When i use the while(resultSet.next()), the loop runs untill 10 records and after that when it come to the while check it hangs.
    Sample code
    pstmt= conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    rs = pstmt.executeQuery();
    while (rsAccessNoEq.next()) {...
    Then i added the code in the while loop
    if(rs.isLast()){
    return;
    For the first iteration itself the theisLast() is true and it terminates from the loop.
    Please help me

    public class ISP {
         private GFA gestorFic = null;
         private GCA gestorCad = null;
         private GBDAgestor = null;
         private String path = null;
         ServiceProcessVO javaIntra = null;
         ServiceProcessVO javaIntra1 = null;
         ServiceProcessVO javaIntra2 = null;
         ServiceProcessVO javaIntra3 = null;
         ArrayList dataList = null;
         List dataFile = null;
         ArrayList dataList1 = null;
         ArrayList dataList2 = null;
         ArrayList dataList3 = null;          
         public final void iP() throws SQLException,
         MCEA {
         ResultSet rsIntraHq = null;
              Connection connIntraHq = null;
              PreparedStatement pstmtIntraHq = null;
              ResultSet rsIntraFlow = null;
              Connection connIntraFlow = null;
              PreparedStatement pstmtIntraFlow = null;
              ResultSet rsEqNoAccess = null;
              Connection connEqNoAccess = null;
              PreparedStatement pstmtEqNoAccess = null;
              ResultSet rsAccessNoEq = null;
              Connection connAccessNoEq = null;
              PreparedStatement pstmtAccessNoEq = null;
              ResultSet rsFlowHqAccess = null;
              Connection connFlowHqAccess = null;
              PreparedStatement pstmtFlowHqAccess = null;
              dataList = new ArrayList();          
              dataFile = new ArrayList();
              System.out.println("At the begining :"+now() );
              dataFile = gestorFic.leerArchivo(path, file);
              System.out.println("After first step :"+now() );
              int size1 = dataFile.size();
              try {
                   connAccessNoEq = gestor.getConnection();
                   javaIntra = new ServiceProcessVO();
                   pstmtAccessNoEq = connAccessNoEq
                   .prepareStatement(ConsultasAssets.INTRA_ACCESS_NOEQ);
                             //ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
                   pstmtAccessNoEq.setString(1, oti);
                   pstmtAccessNoEq.setString(2, oti);
                   pstmtAccessNoEq.setString(3, oti);
                   rsAccessNoEq = pstmtAccessNoEq.executeQuery();
                   //int k = rsAccessNoEq.TYPE_SCROLL_SENSITIVE;
                   int i = 0;
                   //rsAccessNoEq.last();
                   while (rsAccessNoEq.next()) {
                        i++; System.out.println("Begin of loop:"+i);
                        javaIntra = populatedata(rsAccessNoEq, true);
                        dataList.add(javaIntra);
                        // Flow Hq Access
                        try {
                             connFlowHqAccess = gestor.getConnection();
                             javaIntra1 = new ServiceProcessVO();
                             pstmtFlowHqAccess = connFlowHqAccess
                             .prepareStatement(ConsultasAssets.HQ_ACCESS);
                             pstmtFlowHqAccess.setString(1, javaIntra
                                       .getCTASOCIACION().trim());
                             pstmtFlowHqAccess.setString(2, rsAccessNoEq.getString(1)
                                       .trim());
                             pstmtFlowHqAccess.setString(3, rsAccessNoEq.getString(3)
                                       .trim());
                             pstmtFlowHqAccess.setString(4,oti);
                             pstmtFlowHqAccess.setString(5,oti);
                             pstmtFlowHqAccess.setString(6,oti);
                             rsFlowHqAccess = pstmtFlowHqAccess.executeQuery();
                             while (rsFlowHqAccess.next()) {
                                  javaIntra1 = populatedata(rsFlowHqAccess, false);
                                  dataList.add(javaIntra1);
    //                         if(rsAccessNoEq.isAfterLast()){
    //                              return;
                        } catch (SQLException se) {
                             MCLA.logFatel(ClassNameAssets
                                       .getQualifiedClassName()
                                       + ": "
                                       + ClassNameAssets.getLineNumber()
                                       + ": "
                                       + "Error Occurred in HQ_ACCESS: "
                                       + se.getMessage());
                             throw new MigracionCommonExceptionAssets(se.getMessage());
                        } finally {
                             pstmtFlowHqAccess.close();
                             if (rsFlowHqAccess != null) {
                                  rsFlowHqAccess.close();
                             //gestor.releaseConn(connFlowHqAccess);
         private SPVOpopulatedata(ResultSet rsCpProcess, boolean modify)
         throws SQLException {
              SPVOjavaIntra = new ServiceProcessVO();
              if (rsCpProcess.getString(ConstantesAssets.NU) != null
                        && !rsCpProcess.getString(ConstantesAssets.NU)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setNU(rsCpProcess.getString(
                             ConstantesAssets.NU).trim());
              if (rsCpProcess.getString(ConstantesAssets.NU_ASO) != null
                        && !rsCpProcess.getString(ConstantesAssets.NU_ASO)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setNU_ASO(rsCpProcess.getString(
                             ConstantesAssets.NU_ASO).trim());
              // HashTable logic to increament value for CTASOCIACION Start
              if (modify == true) {
                   if (rsCpProcess.getString(ConstantesAssets.CTASOC) != null
                             && !rsCpProcess.getString(ConstantesAssets.CTASOC)
                             .equalsIgnoreCase(ConstantesAssets.BLANK)) {
                        char cha = ConstantesAssets.A;
                        if (tempMap.get(javaIntra.getNU()) != null) {
                             cha = tempMap.get(javaIntra.getNU()).toString()
                             .charAt(0);
                             cha++;
                        tempMap.put(javaIntra.getNU(), Character
                                  .toString(cha));
                        javaIntra.setCTASOCIACION(((rsCpProcess
                                  .getString(ConstantesAssets.CTASOC).trim()) + cha)
                                  .trim());
              } else {
                   javaIntra.setCTASOCIACION(rsCpProcess.getString(
                             ConstantesAssets.CTASOC).trim());
              // HashTable logic to increament value for CTASOCIACION End
              if (rsCpProcess.getString(ConstantesAssets.CCC) != null
                        && !rsCpProcess.getString(ConstantesAssets.CCC)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setCCC(rsCpProcess.getString(
                             ConstantesAssets.CCC).trim());
              if (rsCpProcess.getString(ConstantesAssets.FIV1) != null
                        && !rsCpProcess.getString(ConstantesAssets.FIV1)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setFIV(rsCpProcess.getString(
                             ConstantesAssets.FIV1).trim());
              if (rsCpProcess.getString(ConstantesAssets.FFV) != null
                        && !rsCpProcess.getString(ConstantesAssets.FFV)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setFFV(rsCpProcess.getString(
                             ConstantesAssets.FFV).trim());
              if (rsCpProcess.getString(ConstantesAssets.ES) != null
                        && !rsCpProcess.getString(ConstantesAssets.ES)
                        .equalsIgnoreCase(ConstantesAssets.BLANK))
                   javaIntra.setES(rsCpProcess.getString(
                             ConstantesAssets.ES).trim());
              javaIntra.setI(ConstantesAssets.N);
              javaIntra.setN(ConstantesAssets.BLANK);
              javaIntra.setC(ConstantesAssets.BLANK);
              javaIntra.setCO(ConstantesAssets.BLANK);
              javaIntra.setFI(ConstantesAssets.BLANK);
              return javaIntra;
    Please see the code
    Siva

  • Resultset next() return true even there's not record

    Here's the code:
    public Object getColumn(String s) throws SQLException {
    Object o = null;
    ResultSet r = db.select(s); // a db rpocess return a resulset
    int Columns = r.getMetaData().getColumnCount();
    if (Columns == 1) {
    Vector v = new Vector();
    while (r.next()) {
    v.add(r.getString(1));
    o = v;
    } else if (Columns == 2) {
    Hashtable h = new Hashtable();
    while (r.next()) { // <----problem in this line =============
    h.put(r.getString(1), ( (r.getString(2) == null) ? "" : r.getString(2)));
    o = h;
    return o;
    j2se 1.4.1 (with the Jbuilder8) and hsqldb 1.7.1
    actually, it works if we got records in the resultset, but the next() is true even there's not record returned.

    Nothing to do with your problem but this line could cause other problems
    h.put(r.getString(1), ( (r.getString(2) == null) ? "" : r.getString(2)));You are retrieving the same column twice. Some JDBC drivers throw an exception if you try doing this.

  • The ResultSet.next() returns false....

    Hai,
    I am working on jdbc. The connection credentials all correct, and its getting connected to the sybase without any problems. But I am not able to perform any 'select' or "update" statements...There are no exception or any errors...But the ResultSet.next() returns false and executeUpdate returns 0 . .
    I think you can help me.....Thanks...

    Yes the query is sameAs already pointed out, there are ONLY two possibilities.
    1. The query is not the same
    2. The database is not the same.
    You are making assumptions about what is going on and then drawing conclusions.
    You need to understand that you assumptions are wrong. So it doesn't matter what conclusion you draw.
    In terms of why the query isn't the same there could be any number of reasons but usually it is because you are passing in data and that data isn't what you think (assume) it is. It can also be that you are constructing the SQL and that construction is different. It could be that the environment that you use to test as settings which impact SQL.

  • Lockup in ojdbc14 Resultset.next()

    After several loops through the ResultSet handler, a subsequent call to ResultSet.next() results in a lockup.
    Below is a partial stack dump.
    Thread [Thread-14] (Suspended)
         oracle.jdbc.driver.SensitiveScrollableResultSet(oracle.jdbc.driver.ScrollableResultSet).prepare_refetch_statement(int) line: 2299 [local variables unavailable]
         oracle.jdbc.driver.SensitiveScrollableResultSet(oracle.jdbc.driver.ScrollableResultSet).refreshRowsInCache(int, int, int) line: 292
         oracle.jdbc.driver.SensitiveScrollableResultSet.refreshRow() line: 174
         oracle.jdbc.driver.SensitiveScrollableResultSet.handle_refetch() line: 255
         oracle.jdbc.driver.SensitiveScrollableResultSet.next() line: 82
         oracle.jdbc.driver.UpdatableResultSet.next() line: 251
         com.solcom.labelprintroom.DatabaseAccess.ordersForUserStatus(com.solcom.centraldb.CDBUser, java.lang.String) line: 291
    prepare_refetch_statement(int) is continuously looping between lines 2299, 2304, 2305.
    Connection is to an Oracle 8i (8.1.7) database.
    No exception is thrown and no timeout occurs. it merely loops continuously between the lines described in the Oracle driver.
    Is this a known problem? Is there a workaround?
    TIA
    AndyB

    "I have two DA classes with virtually the same code, just different queries."
    "In the other DA i do exactly the same..."Are these contradictory statements?
    Does anyone know if there is a problem with the Oracle
    Drivers or has anyone encountered a similair problem?Well, I am positive that -1 is not a problem for Oracle, it can use almost all the small negative numbers without error...
    Would it be possible to post a bit of your code to demonstrate how the code is different and how the SQL is different (or the same / not sure). There are infinite ways to code SQL with -1 in it, so what is important is exactly how you did it, which driver you are using, if you are using a Statement or PreparedStatement, if you are using connection pooling, etc.

  • BUG JSF h:dataTable with JDBC ResultSet - only last column is updated

    I tried to create updatable h:dataTable tag with three h:inputText columns with JDBC ResultSet as data source. But what ever I did I have seceded to update only the last column in h:dataTable tag.
    My JSF page is:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=windows-1250"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1250"/>
    <title>Stevan</title>
    </head>
    <body><h:form>
    <p>
    <h:messages/>
    </p>
    <p>
    <h:dataTable value="#{tabela.people}" var = "record">
    <h:column>
    <f:facet name="header">
    <h:outputText value="PIN"/>
    </f:facet>
    <h:inputText value="#{record.PIN}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Surname"/>
    </f:facet>
    <h:inputText value="#{record.SURNAME}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name"/>
    </f:facet>
    <h:inputText value="#{record.NAME}"/>
    </h:column>
    </h:dataTable>
    </p>
    <h:commandButton value="Submit"/>
    </h:form></body>
    </html>
    </f:view>
    My java been is:
    package com.steva;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class tabela {
    private Connection conn;
    private ResultSet resultSet;
    public tabela() throws SQLException, ClassNotFoundException {
    Statement stmt;
    Class.forName("oracle.jdbc.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "hr", "hr");
    stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    resultSet = stmt.executeQuery("SELECT PIN, SURNAME, NAME FROM PERSON");
    public ResultSet getPeople() {
    return resultSet;
    I have instaled “Oracle Database 10g Express Edition Release 10.2.0.1.0” – product on my PC localy. I have enabled HR schema and I have instaled and pupulated with sample data folloving table:
    CREATE TABLE "PERSON"
    (     "PIN" VARCHAR2(20) NOT NULL ENABLE,
         "SURNAME" VARCHAR2(30),
         "NAME" VARCHAR2(30),
         CONSTRAINT "PERSON_PK" PRIMARY KEY ("PIN") ENABLE
    I have:
    Windows XP SP2
    Oracle JDeveloper Studio Edition Version 10.1.3.1.0.3894
    I am not shure why this works in that way, but I think that this is a BUG
    Thanks in advance.

    Hi,
    I am sorry because of formatting but while I am entering text looks fine but in preview it is all scrambled. I was looking on the Web for similar problems and I did not find anything similar. Its very simple sample and I could not believe that the problem is in SUN JSF library. I was thinking that problem is in some ResultSet parameter or in some specific Oracle implementation of JDBC thin driver. I did not try this sample on any other platform, database or programming tool. I am new in Java and JSF and I have some experience only with JDeveloper.
    Java been(session scope):
    package com.steva;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    public class tabela {
    private Connection conn;
    private ResultSet resultSet;
    public tabela() throws SQLException, ClassNotFoundException {
    Statement stmt;
    Class.forName("oracle.jdbc.OracleDriver");
    conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@localhost:1521:xe", "hr", "hr");
    stmt = conn.createStatement
    (ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    resultSet = stmt.executeQuery("SELECT PIN, SURNAME, NAME FROM PERSON");
    public ResultSet getZaposleni() {
    return resultSet;
    JSF Page:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=windows-1250"%>
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <f:view>
    <html>
    <head>
    <meta http-equiv="Content-Type"
    content="text/html; charset=windows-1250"/>
    <title>Stevan</title>
    </head>
    <body><h:form>
    <p>
    <h:messages/>
    </p>
    <p>
    <h:dataTable value="#{tabela.zaposleni}" var = "record">
    <h:column>
    <f:facet name="header">
    <h:outputText value="PIN"/>
    </f:facet>
    <h:inputText value="#{record.PIN}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Surname"/>
    </f:facet>
    <h:inputText value="#{record.SURNAME}"/>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Name"/>
    </f:facet>
    <h:inputText value="#{record.NAME}"/>
    </h:column>
    </h:dataTable>
    </p>
    <h:commandButton value="Submit"/>
    </h:form></body>
    </html>
    </f:view>

  • Using objects rather than jdbc resultset to fill reports

    Hi buddies!
    I�m developing a small sample of application that generates reports using values retrieved from objects.
    The idea is simple, I have an arraylist of objects and want to fill my report which these objects atributes.
    Jasper Project API has a class called JasperFillManager which is used to fill reports and takes 3 arguments, for instance:
    JasperFillManager.fillReport(JasperReport reporttofill,HashMap parameters, JRDataSource dataSource)
    I�ve created a custom JRDataSource named fonteDadosJasperCustomizada
    This class implements an arraylist of objects and two methods from the interface JRDataSource which are responsible for giving the values to fill the report. This class doesn�t take values from a resultset! ;)
    but for some reason nothing appears to me after executing the application... everything is alright I think the might be a mistake in the interface methods, the report also is alright.
    All sugestions are welcome
    thanks
    import java.sql.*;
    import java.util.HashMap;
    import java.util.Map;
    import net.sf.jasperreports.engine.JasperCompileManager;
    import net.sf.jasperreports.engine.JasperFillManager;
    import net.sf.jasperreports.engine.JasperPrint;
    import net.sf.jasperreports.engine.JasperReport;
    import net.sf.jasperreports.engine.design.JasperDesign;
    import net.sf.jasperreports.engine.xml.JRXmlLoader;
    import net.sf.jasperreports.view.JasperViewer;
    public class relatorioteste1{
         public relatorioteste1(){
         try{     
              fonteDadosJasperCustomizada fonte = new fonteDadosJasperCustomizada();
              JasperDesign relatoriocarregado = JRXmlLoader.load("c:/relatorioteste1.jrxml");          
              JasperReport relatoriocompilado = JasperCompileManager.compileReport(relatoriocarregado);
              /*the parameter fonte being passed to fillManager is a custom JRDataSource.
              * The default JRResultSetDataSource only receives a JDBC ResultSet and
              * extracts Data from it to fill the Report, such Object is implements
              * the JRDataSource interface which defines methods that are used by
              * fillManager to obtain data from the ResultSet.
              * My intention is to create my own JRDataSource class which should
              * be able to retrieve data from objects instead of ResultSet
              * See class fonteDadosJasperCustomizada for details
              JasperPrint relatorioimpresso = JasperFillManager.fillReport(relatoriocompilado,new HashMap(),fonte);
              JasperViewer.viewReport(relatorioimpresso);
         catch(Exception e){
              javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
         public static void main(String args[]){
              new relatorioteste1();
    import net.sf.jasperreports.engine.JRDataSource;
    import net.sf.jasperreports.engine.JRException;
    import net.sf.jasperreports.engine.JRField;
    import java.util.ArrayList;
    public class fonteDadosJasperCustomizada implements JRDataSource {
         public Object getFieldValue(JRField arg0) throws JRException{
         /*The following line returns the next object(aluno) from
         * the arraylist collection
              Aluno aluno = (Aluno) dados.listIterator().next();
         /*This block verifies which column value(field) is being
         * requested by the jasperFillManager.fillReport and returns
         * an object value corresponding to the field
              if ("codigo".equals(arg0.getName()))
                   return Integer.valueOf(aluno.getCodigo());
              else if ("nome".equals(arg0.getName()))
                   return aluno.getNome();
              else
                   return Integer.valueOf(aluno.getIdade());     
              public boolean next() throws JRException{
              /*this decision verifies if there�re more elements in
              * the arraylist collection if so returns true... else returns
              * false
              if (dados.listIterator().hasNext())
                   return true;
              else
                   return false;
         public fonteDadosJasperCustomizada(){
              /*The constructor of my custom JRResulSetDataSource should receive
              * a JDBC ResultSet in place of an Arraylist of Objects
              * The atributes of each object is mapped to a field in
              * jasperreports template
              dados = new ArrayList();
              dados.add(new Aluno(1,"charlles cuba",25));
              dados.add(new Aluno(2,"Maicom napolle",25));
              dados.add(new Aluno(3,"Gustavo castro",21));          
         public static void main(String args[]){
              new fonteDadosJasperCustomizada();
         ArrayList dados;     
    }

    Buddies thansk everyone
    I�m really grateful... the previous post in here was very useful to me. I
    was wrong about ArrayList.listIterator.
    I finnaly generated a report from an arraylist of objects.
    Here�s the code... I made some changes the first one was wrong
    HERE IS MY MAIN CLASS RESPONSIBLE FOR GENERATING THE REPORT
    public class relatorioteste1{     
         public relatorioteste1(){
              try{     
                   fonteDadosJasperCustomizada fonte = new fonteDadosJasperCustomizada();
                   JasperDesign relatoriocarregado = JRXmlLoader.load("c:/relatorioteste1.jrxml");          
                   JasperReport relatoriocompilado = JasperCompileManager.compileReport(relatoriocarregado);                    
                   JasperPrint relatorioimpresso = JasperFillManager.fillReport(relatoriocompilado,new HashMap(),fonte);
                   JasperViewer.viewReport(relatorioimpresso);
              catch(Exception e){
                   javax.swing.JOptionPane.showMessageDialog(null, e.getMessage());
         public static void main(String args[]){
              new relatorioteste1();
    HERE IS MY CUSTOM JRDATASOURCE
    public class fonteDadosJasperCustomizada implements JRDataSource {
         public Object getFieldValue(JRField arg0) throws JRException{     
              if ("codigo".equals(arg0.getName()))
                   return Integer.valueOf(aluno.getCodigo());
              else if ("nome".equals(arg0.getName()))
                   return aluno.getNome();
              else
                   return Integer.valueOf(aluno.getIdade());
         public boolean next() throws JRException{
              if (iterator.hasNext()){
                   aluno = (Aluno) iterator.next();                    
                   return true;
              else
                   return false;          
         public fonteDadosJasperCustomizada(){          
              dados = new ArrayList();
              dados.add(new Aluno(1,"charlles cuba",25));
              dados.add(new Aluno(2,"Maicom napolle",25));
              dados.add(new Aluno(3,"Gustavo castro",21));
              iterator = dados.listIterator();
         public static void main(String args[]){
              new fonteDadosJasperCustomizada();
         ArrayList dados;
         Iterator iterator;
         Aluno aluno;
    }

  • WL 6.1 sp3 and ResultSet.next()

    Has anyone else had a problem with this call ?
    I'm running this on Win2000 and Oracle 8.1.6.
    ResultSet.next() seems to return true even after the cursor has passed the last row in the set. This was not an issue with WL6.1 sp1.

    I got the same problem. But finally I found that this is the problem with WL 6.1. This is resolved in sp3.
    So please verify the exact version of weblogic you are using.
    Note : Start weblogic from some sample domain before executing the following.
    java -classpath <wl_install_dir>/wlserver6.1/lib/weblogic.jar weblogic.Admin -url T3://<host>:<port> VERSION
    You should get similar to....
    WebLogic Server 6.1 SP3 06/19/2002 22:25:39 #190835
    WebLogic XML Module 6.1 SP3 06/19/2002 22:39:10 #190835

  • ResultSet.next() throws exception

    I am working on a BEA Weblogic application migration from 7.1 to 8.1. My application has lots of Oracle user defined package functions for providing database query. Those functions return a cursor pointing to the query results (ResultSet object in JDBC). My BEA Weblogic 8.1 java application, which invokes those Oracle functions, uses getObject() method to get query ResultSet. Follows are a java code snippet and exception thrown when using ResultSet.next() method to move cursor. Thanks.
    =================== code snippet ========================
    CallableStatement cs1 = (CallableStatement)conn.prepareCall("{? = call pkg_profile.fn_get_user_data(?) }");
    cs1.registerOutParameter(1, java.sql.Types.OTHER);
    cs1.setString (2, c_strUsername);
    cs1.execute();
    // Get the Result
    ResultSet rs1 = (ResultSet)cs1.getObject(1);
    if (rs1 == null || !rs1.next()) { <=== exception thrown due to moving cursor to the next row of query result.
    =================== code snippet =======================
    Exception -
    ERROR 24 Nov 2004 12:19:28,527 USER:supuser - CNTXT:MISUserProfile.userDataDispatcher | SQL Error while retrieving data for user. | java.sql.SQLException: java.lang.NullPointerException: CDA is null
    Start server side stack trace:
    java.lang.NullPointerException: CDA is null
    at weblogic.db.oci.OciCursor.arrayFetch(Native Method)
    at weblogic.db.oci.OciCursor.oci_arrayFetch(OciCursor.java:2338)
    at weblogic.jdbc.oci.ResultSet.next(ResultSet.java:774)
    at weblogic.jdbc.rmi.internal.ResultSetImpl.next(ResultSetImpl.java:135)
    at weblogic.jdbc.rmi.internal.ResultSetImpl_WLSkel.invoke(Unknown Source)
    at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
    at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:821)
    at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:308)
    at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
    End server side stack trace

    Try this one...
    Before excecuting the query setAutoCommit false and then try to execute the query.After executing query manually do commit.It should work.

  • Hi resultset.previuos() - problem

    Hi all.
    Im working with jdbc.odbc standart bridge.
    when I try to do resultset.previous() I get an exception taht I cant fetch backwards.
    So I tried to change the statement propertites to somthing like - .TYPE_SCROLL_SENSITIVE
    now I dont get the exceptions but I cant fetch forwards: resultset.next() returns false.
    I also tried to change the direction by calling resultset.setFetchDirection()
    any ideas?
    10x Yonatan

    The jdbc/odbc bridge has known limitations over a pure jdbc driver, this is probably what you're running into. I'd suggest trying to get a hold of a jdbc driver for your database.

  • Resultset.next hangs waiting for socketread()

    Hi All,
    I am running an application which is trying to fetch a set of records using jdbc resultset but , sometimes, it hangs on the socketread and I am not sure what is the cause..Please help:
    Below is the piece of code and parameters are:
    start=1
    iBreakingLimit=30 when it hangs
    QueryTimeout=60 sec
    limit=60
    Hangs at:
    SocketInputStream.socketRead()
    OracleResultSet.close_or_fetch_from_next(boolean)
    ScrollableResultSet.next()
    dbStatement=dbConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
                                          if(start>1)
                        rs.absolute(start-1);
                   int iBreakingLimit=0;
                   while (rs.next())
                        ++iBreakingLimit;
                        if(limit>0 && iBreakingLimit>limit)
                             break;
                                      }Edited by: Amer on Apr 15, 2009 7:49 AM
    Edited by: Amer on Apr 15, 2009 7:50 AM
    Edited by: Amer on Apr 15, 2009 7:50 AM
    Edited by: Amer on Apr 15, 2009 7:51 AM

    Hi Again,
    I wrote a sample class to test the connection and my select statement and I was able to reproduce it outside the application. This class has no update at all and it never returns (hangs at iteration number 7 for the first loop).... Another test (removing timeout set which I think it is not related) shows that it stops at Iteration 4 breaking limit 40 (so it is random).. Also, I tried with TRANSACTION_SERIALIZABLE and got same behavior . THIS does NOT happen with db2 driver using same sample.. Please help!!
    package com.udm.core.test;
    import java.sql.*;
    public class JDBCTest
         public static void main(String s[])
              JDBCTest t = new JDBCTest();
              try
                   for(int i=0;i<30;i++)
                        System.out.println("Call ="+i);
                        t.testme();
              catch(Exception e)
                   e.printStackTrace();
         public void testme() throws Exception
              String sUrl="jdbc:oracle:thin:";
              String sServer="xxxxxxxxxx";
              String sPort="xxxx";
              String sService="xxxxx";
              String sDriver = "oracle.jdbc.OracleDriver";
              String sUserName="xxxx";
              String sPassword="xxxxxx";
              String sSQL="select about 270 fields from table (pure select statement)";     
              Class<?> cDriverClass=Class.forName(sDriver);
              Driver dDriverObject=(java.sql.Driver)cDriverClass.newInstance();
              DriverManager.registerDriver (dDriverObject);
              String sServiceUrl=sUrl+"@"+sServer+":"+sPort+":"+sService;
              Connection dbConnection=DriverManager.getConnection (sServiceUrl,sUserName,sPassword);
              dbConnection.setAutoCommit(false);
              dbConnection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
              Statement dbStatement =dbConnection.createStatement();
              dbStatement.setQueryTimeout(60);
              ResultSet rs=dbStatement.executeQuery(sSQL);
              int iBreakingLimit=0;
              int limit=200;
              while (rs.next())
                   ++iBreakingLimit;
                   if(limit>0 && iBreakingLimit>limit)
                        break;
                   System.out.println("\tInside loop iBreakingLimit="+iBreakingLimit);
              rs.close();
              dbStatement.close();
    }Thread dump:
    Call =7
    Full thread dump Java HotSpot(TM) Client VM (1.5.0_16-b02 mixed mode):
    "OracleTimeoutPollingThread" daemon prio=10 tid=0x0ac89868 nid=0x1380 waiting on condition [0x0af0f000..0x0af0fbe8]
    at java.lang.Thread.sleep(Native Method)
    at oracle.jdbc.driver.OracleTimeoutPollingThread.run(OracleTimeoutPollingThread.java:158)
    "Low Memory Detector" daemon prio=6 tid=0x00a955e0 nid=0xeb4 runnable [0x00000000..0x00000000]
    "CompilerThread0" daemon prio=10 tid=0x00a942f8 nid=0xb30 waiting on condition [0x00000000..0x0abcfa48]
    "Signal Dispatcher" daemon prio=10 tid=0x00a93660 nid=0x172c waiting on condition [0x00000000..0x00000000]
    "Finalizer" daemon prio=8 tid=0x00a8a440 nid=0x12f0 in Object.wait() [0x0ab4f000..0x0ab4fa68]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x02fd5d00> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:120)
    - locked <0x02fd5d00> (a java.lang.ref.ReferenceQueue$Lock)
    at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:136)
    at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    "Reference Handler" daemon prio=10 tid=0x00a89008 nid=0xa58 in Object.wait() [0x0ab0f000..0x0ab0fae8]
    at java.lang.Object.wait(Native Method)
    - waiting on <0x02fd5d88> (a java.lang.ref.Reference$Lock)
    at java.lang.Object.wait(Object.java:474)
    at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
    - locked <0x02fd5d88> (a java.lang.ref.Reference$Lock)
    "main" prio=6 tid=0x00036af8 nid=0x1450 runnable [0x0007f000..0x0007fc3c]
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at oracle.net.ns.Packet.receive(Unknown Source)
    at oracle.net.ns.DataPacket.receive(Unknown Source)
    at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
    at oracle.net.ns.NetInputStream.read(Unknown Source)
    at oracle.jdbc.driver.T4CMAREngine.getNBytes(T4CMAREngine.java:1520)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalNBytes(T4CMAREngine.java:1490)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalBuffer(T4CMAREngine.java:2004)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalCLR(T4CMAREngine.java:1791)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalCLR(T4CMAREngine.java:1925)
    at oracle.jdbc.driver.T4CMAREngine.unmarshalDALC(T4CMAREngine.java:2347)
    at oracle.jdbc.driver.T4C8TTIuds.unmarshal(T4C8TTIuds.java:134)
    at oracle.jdbc.driver.T4CTTIdcb.receiveCommon(T4CTTIdcb.java:154)
    at oracle.jdbc.driver.T4CTTIdcb.receive(T4CTTIdcb.java:114)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:703)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
    at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1124)
    at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1272)
    - locked <0x02b2f5b0> (a oracle.jdbc.driver.T4CPreparedStatement)
    - locked <0x02b18e30> (a oracle.jdbc.driver.T4CConnection)
    at com.udm.core.test.JDBCTest.testme(JDBCTest.java:50)
    at com.udm.core.test.JDBCTest.main(JDBCTest.java:15)
    "VM Thread" prio=10 tid=0x00a86540 nid=0xfec runnable
    Edited by: Amer on Apr 17, 2009 6:45 AM
    Edited by: Amer on Apr 17, 2009 6:45 AM
    Edited by: Amer on Apr 17, 2009 6:47 AM
    Edited by: Amer on Apr 17, 2009 6:48 AM
    Edited by: Amer on Apr 17, 2009 6:58 AM
    Edited by: Amer on Apr 17, 2009 7:05 AM

  • Resultset.next() Issue

    Okay I have narrow my issue down to activity involved with the resultset.next() method. What is happening is I am working through a small resultset--3 records. These records are made up of columns from 3 seaprate tables (9 total). Some of these tables have many records (> 3K) in them. I moved the SQL statement in a store procedure so we can execute the query in a faster manner. The store procedure is returning the information in only 46ms. However, when I start looking through the resultset on the app server, it is taking 19K ms for the first time through the loop.
    I am at a lost to explain why the first iteration is taking so long. I have looked back at the SQL statement. I use alias names for the tables. I identify the column names in the select statement, but I do not use aliases for the column names. I am wondering if my problem is connected to the fact that the Oracle Driver
    maybe going back to get the column names the first time through the result set. I am not using the column name to index into the resultset. If my theory is right, this would explain the high latency. If I am wrong, I am stumped.
    Any suggestions or help explaining this would be greatly appreciated.
    As always, thanks for reading my post.
    Russ

    Execution of a CallableStatement (Procedure) is relatively fast. Getting ResultSet back is fast. But First iteration over the result set takes a lot of time comparing to the following iterations.
    Part of the code :
    long start=System.currentTimeMillis();
    int i=0;
    long local=System.currentTimeMillis();
    while(rs.next()){
    if (i==0){
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",local);
    local=System.currentTimeMillis();
    hol=new ResultSetRowHolder(rs);
    list.add(hol);
    i++;
    if (i%100==0){
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",local);
    local=System.currentTimeMillis();
    MetricsUtil.printTime("ResultSetRowHolder.getRows(ResultSet rs) ["+list.size()+" ]",start);
    Printouts
    Metrics << QueryHelper.executeStatement() >> Total time -> 2.836 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [0 ] >> Total time -> 13.867 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [100 ] >> Total time -> 0.48 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [200 ] >> Total time -> 0.44 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [300 ] >> Total time -> 0.47 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [400 ] >> Total time -> 0.38 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [500 ] >> Total time -> 0.37 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [600 ] >> Total time -> 0.38 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [700 ] >> Total time -> 0.35 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [800 ] >> Total time -> 0.34 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [900 ] >> Total time -> 0.32 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1000 ] >> Total time -> 0.34 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1100 ] >> Total time -> 0.41 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1200 ] >> Total time -> 0.32 sec
    Metrics << ResultSetRowHolder.getRows(ResultSet rs) [1230 ] >> Total time -> 14.340 sec

  • Casting a JDBC resultSet to VO RowSet?

    Is it possible to somehow transform a plain vanilla jdbc ResultSet to a VO RowSet? (Of course without iterating!) Either by passing the entire object (with all rows intact) or by casting?
    Thanks
    -Nat
    PS. Rob, you know why I want to do this, right&lt;g&gt;?

    We use JDBC to access the database internally. BC4J automates a best-practice use of JDBC PreparedStatements and ResultSet's for you without your having to worry about remembering the low-level details.
    Our generic JDBC-interaction code worries about consistently applying the best-practice and highest-performance JDBC techniques for you. When we discover a further improvement and implement it, all of your view objects immediately benefit in the next release.
    We had a team in Oracle Applications who claimed they could read large amounts of data faster with hand-coded JDBC than with BC4J. They weren't using BC4J in the optimal way and I illustrated by modifying their benchmark how to make BC4J be faster than hand-coded raw use of JDBC.
    Their benchmark wasn't really comparing apples to apples, so I made sure they were comparing roughly equivalent amounts of work before we could conclude what was better.

  • Creating XML from JDBC resultset

    Can anyone give me a pointer as the best way to create XML from a JDBC resultset. I have told that XSU cannot be used as it is vendor specific and ties us to Oracle (yawn, yawn).
    Any ideas welcomed.

    import javax.xml.parsers.*;
    import org.w3.dom.*;
    import javax.xml.dom.*;
    import javax.xml.dom.source.*;
    import javax.xml.dom.stream.*;
    import java.sql.*;
    public class CreateXML{
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db=dbf.newDocumentBuilder();
    Document doc=db.newDocument();
    Element root=doc.createElement("root_element");
    // coonect to database
    //get resultset metadata rsmd
    while(rs.next()){
    Element row=doc.createElement("row");
    for(int j=1;j<=rsmd.getColumnCount();j++){
    String colName=rsmd.getCoulmName(j);
    String colValue=rs.getString(j);
    Element e=doc.createElement(colName);
    e.appendChild(doc.createTextNode(colValue));
    row.appendChild(e);
    root.appendChild(row);
    doc.appendChild(root);
    //You can now use XSLT to generate xml file thus:
    TransformerFactory tmf=TransformerFactory.newInstance();
    Transformer tf=tmf.newTransformer();
    DOMSource source=new DOMSource(doc);
    StreamResult result=new StreamResult("name of file for output");
    tf.transform(source,result);
    // of course exceptions will have to be caught in this code.

Maybe you are looking for

  • How do I install iCloud on Windows Vista?

    I think the current iCloud can only be installed to Windows 7 or 8, so where can I get the earlier version from?

  • Getting phone out of iTunes recovery mode loop

    A while back I dropped my iPhone 4 in the bath, everything worked fine apart from the home button which didn't work at all and when my phone was completely flat and I put it on charge it would tell me to connect to iTunes, I used to solve this my unp

  • ITunes will not let me sign-in after updating

    device: Mac Mini Intel core 2 duo operating system installed:  Mac OS X v10.6.8 version of iTunes installed on my computer is:  iTunes 10.4 Details: After I upgraded to latest Itunes, the sign-in function is grayed out after I enter my apple ID. not

  • Certificate of Completion with Date Stamp

    Greetings, Is it possible to make a form that will automatcally add a date stamp to it.? Here is the scenario: a user completes a series of questions through an eLearning module. At the end of it, they click on a button/link that takes them to a page

  • My iTunes Match isn't working. How can I fix this?

    How can I fix my iTunes Match?