Jdbc resultset problem

Hi all
i'm gtting a problem with the action listener event of my "Next" and "Previous" Jbuttons. The code that i have written makes the program search only for the next record and not further...and sameproblem for previous button.
That is: If originally i'm on the 3rd record, when i press next it goes to 4th record and when i press next again nothing happens. The same applies to my previous event.
Can anyone give me a hint on how to solve this problem?
i post my code below:
next.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent evt)
                    try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql:///Super","root","");
Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
s.execute("SELECT * FROM tblcustomer");
     ResultSet rs = s.getResultSet();
     rs.next();
          cus.setText(rs.getString(1));
          fname.setText(rs.getString(2));
          lname.setText(rs.getString(3));
          txtadd.setText(rs.getString(4));
          txtcity.setText(rs.getString(5));
          txtcountry.setText(rs.getString(6));
          catch (Exception e)
          JOptionPane.showMessageDialog(null,"No further record available!");
});

thanx for your help but i still can't access the second record
here is my code below, have a look at it:
Class.forName("com.mysql.jdbc.Driver").newInstance();
final Connection conn=DriverManager.getConnection("jdbc:mysql:///Super", "root","");
previous.addActionListener(new ActionListener(){
               public void actionPerformed(ActionEvent evt)
                    try
                         final Statement s= conn.createStatement();
                    s.execute("SELECT * FROM tblcustomer");
          ResultSet rs = s.getResultSet();
                    if (!rs.isFirst())
                    while ( rs.previous() ){
                    rs.relative(-1);
                    cus.setText(rs.getString("Customer_ID"));
                    fname.setText(rs.getString("First_Name"));
                    lname.setText(rs.getString("Last_Name"));
                    txtadd.setText(rs.getString("Address"));
                    txtcity.setText(rs.getString("City"));
                    txtcountry.setText(rs.getString("Country"));
                    catch (Exception e)
          JOptionPane.showMessageDialog(null,"No further record available!");
          );

Similar Messages

  • JDBC Resultset Problem with ORACLE 10.1.0.2

    Hello
    I have a problem with Petstore GenericCatalogDAO. java. The problem is the behaviour of the resultset object when retrieving data from the database.Below are two synareos one that
    works (when) hard coded and one that does not work when parameter values passed into the the result set.
    1. The code the WORKS.
    statement = connection.prepareStatement("select name from employee where a.name ='SMITH' order by name"
    ,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    The code that gives me a 'exhausted resultset' error which I think means no results
    String[] parameterValues = new String[] { "SMITH" };
    statement = connection.prepareStatement("select name from employee where a.name =? order by name ",
    ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    for (int i = 0; i < parameterValues.length; i++) {
    statement.setString(i + 1, parameterValues);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    There is obviously a problem using these named parametevalues with these preparedstatement resultset, Does anybody know anything about this and a fix for it????
    Cheers. Roger

    Roger,
    It's probably a mistake you made when posting your code, but your query string is incorrect it should be either:
    select name from employee where name = 'SMITH' order by nameor
    select a.name from employee a where a.name = 'SMITH' order by a.nameIn other words you have prefixed a column with a table alias but have not indicated a table alias in the query.
    Also, shouldn't your code be:
    for (int i = 0; i < parameterValues.length; i++) {
        statement.setString(i + 1, parameterValues[ i ]);
    }Or was the "[ i ]" part giving you trouble? (Since "[ i ]" -- without the spaces -- is treated as a text-formatting tag.)
    While I didn't try your specific query, I have no problem using "PreparedStatment"s with parameters.
    What is your environment? Mine is:
    Oracle 10g (10.1.0.4) database on Linux (Red Hat)
    JDK 1.4.2
    ojdbc14.jar JDBC driver (latest version)
    Good Luck,
    Avi.

  • 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>

  • How to implement paging on SQLSERVER JDBC ResultSet?

    Dear experts,
    Please show me somre tips to implement paging on an JDBC resultset?
    Thanks in advanced.

    JSP pagination ? how many records per page ?

  • 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;
    }

  • Pass a jdbc resultset in to a Stored Procedure

    Any answer to the following question would be highly appreciated:
    How can we pass a jdbc resultset in to a Stored Procedure?
    Thanks.

    You could use Oracle's ANYDATASET type or declare schema TYPEs to support passing the data in a known structure. See "Working with Oracle Collections" in the "JDBC Developer's Guide and Reference" on technet.

  • MSSQLServer jdbc connect problem on ODI 11G R2

    I have a MS SQL Server jdbc connect problem on ODI 11G R2 / Windows server 2008 64 bits.
    Tried, one by one, all versions of Microsoft drivers.
    Sqljdbc4.jar copied to : %appdata%\odi\oracledi\userlib\
    The Topology connect syntax is :
    driver: com.microsoft.sqlserver.jdbc.SQLServerDriver
    URL : jdbc:sqlserver://<host>:1433
    => All the topology tests end with time-outs.
    Installed 10G ODI.
    Works with 1.4 java and sqljdbc.jar version 2 jdbc driver.
    Times out with version 3 and/or Sqljdbc4.jar + JAVA_HOME & ODI_JAVA_HOME set to 1.6 path.
    also tried, with no success (time-outs) on either 10g or 11g :
    com.inet.tds.TdsDriver
    jdbc:inetdae7://<host>:1433?database=<DB>
    same results for :
    net.sourceforge.jtds.jdbc.Driver
    jdbc:jtds:sqlserver://<host>:1433
    Any suggestions for a fix?
    Many thanks in advance.

    Hello,
    ODI (11g) Studio is certified on Windows 32 bit only, not on 64bit.
    However you may still install it and configure ODI Studio to run with a 32 bit java.
    Details pls see Master Note For ODI 11g Install Issues And Questions (Doc ID 1214428.1).
    To connect to SQL Server:
    # Check and make sure the authentication mode of your Microsoft SQL Server Server is set to "SQL Server and Windows" or "Mixed", otherwise Oracle Data Integrator (ODI) is unable to connect to the database.
    # Before you create the Oracle Data Integrator (ODI) Dataserver in Topology Manager > Physical Architecture, stop all ODI processes, and place the JDBC Driver file in the ODI's userlib and "/drivers" folder.
    For ODI Studio (Local No Agent)
    %APPDATA%\odi\oracledi\userlib
    %APPDATA% is the Windows Application Data directory for the user (usually C:\Documents and Settings\<user>\Application Data).
    Standalone Agent
    ODI_HOME\oracledi\agent\drivers
    Note: If you decide to use the DataDirect driver that comes with ODI 11g install/ embedded in ODI 11g
    weblogic.jdbc.sqlserver.SQLServerDriver
    Then you don't need to worry about this step.
    # Make sure that the database is the default database of the user account employed by ODI for connection, and that the password is correct.
    # Verify (in your Microsoft SQL Server Server network configuration) that TCP/IP has been enabled on port 1433.
    For more details see How To Set Up JDBC Driver Connections For The Microsoft SQL Server For ODI (Doc ID 423914.1)
    If you try sqljdbc.jar, you need to configure ODI_JAVA_HOME to jdk1.5
    sqljdbc4.jar, jdk1.6 (since ODI 11g requires jdk1.6, I'd suggest sqljdbc4.jar)
    More see Compatibility Matrix For Java Machines And JDBC Drivers Used With ODI (Doc ID 807235.1)
    Hope that helps other people who run into this,
    Edited by: user742480 on Apr 4, 2011 12:06 PM

  • 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.

  • NPE in com.mysql.jdbc.ResultSet

    hi guys,
    config: Connector/J 3.1.11 - mysql 5.0 - java 1.5
    is anybody has ever seen this exception??
    Caused by: java.lang.NullPointerException
            at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:597)
            at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:905)
            at com.mysql.jdbc.ResultSet.getString(ResultSet.java:4977)we've got this exception and we can't understand why!!
    the ResultSet class fragment...
    for (int i = numFields - 1; i >= 0; i--) {
              Integer index = new Integer(i);
              String columnName = this.fields.getName();
              String fullColumnName = this.fields[i].getFullName();
              if (columnName != null) {
                   this.columnNameToIndex.put(columnName, index);
                   this.columnNameToIndex.put(columnName.toUpperCase(), index);
                   this.columnNameToIndex.put(columnName.toLowerCase(), index); // <--- this line caused the exception
              if (fullColumnName != null) {
                   this.fullColumnNameToIndex.put(fullColumnName, index);
                   this.fullColumnNameToIndex.put(fullColumnName.toUpperCase(),
                             index);
                   this.fullColumnNameToIndex.put(fullColumnName.toLowerCase(),
                             index);
    i don't understand why it is possible. columnNameToIndex is protected and only accessed by the ResultSet class. it is in the buildIndexMapping() method and this method is called only in a synchronized method so ???
    any ideas??
    sup@reno

    Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:597)It's an open-source jdbc driver, which maintainted by Mysql. You can try to fix it, and recompile your Connector/J, or report simply Mysql that issue.

  • 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.

  • JDBC MS SQL Server ResultSet Problem

    I'm writing a web-app using apache tomcat. I'm using MS SQL Server 2000 as my database. I am having no problem connecting to the database, but whenever I query the database, the ResultSet that is returned never has anything in it. I've tried even the simplest select queries and i'm still getting no results. I thought it might be a problem with the JDBC Driver I've been using, but I'm using the exact same driver for SQL Squirrel Client to connect, and Squirrel Client is returning results just fine from the database. Is there something that I've forgotten in my servlet code? Here's something like what I've been using:
    Connection con = DriverManager.getConnection(host, userName, password);
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select * from some_table");

    If the select statement returns rows then the loop will execute... Put in some debugging output just before the while() loop, inside the loop, and immediately after the loop.
    Are you ignoring exceptions?
    Google for "jdbc tutorial". Take the simplest example program there that selects something. Run it as a command line program. Does it work? (Answer: yes.) Now what is different between that example program and your code?

  • JDBC ResultSet out of memory problem with Scrollable one

    Hey guys,
    I'm facing the following problem when accessing an Oracle 10g database over oracle jdbc driver 1.4.
    I need to access the rows of a resultset (millions of rows) at least twice. Forward only doesn't need much memory - but I can't do a rs.beforeFirst()
    Switching to ResultSet.TYPE_SCROLL_SENSITIVE gives me always an java.lang.OutOfMemoryError: Java heap space exception after rs.next() and I can see the used memory constantly increasing.
    Here is my test code:
    conn = DriverManager.getConnection
    ("jdbc:oracle:thin:@host:1521:ORCL", "user", "pass");
    Statement my_stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet result = my_stmt.executeQuery("select * from stats_big");
    System.out.println("Query back :)");
    while(result.next()) {      //here happens the error after 200 000 rows
    //make statistics
    //ask user what to do
    result.beforeFirst();
    while(result.next()) {
         //apply function and deliver new values
    conn.close();
    Is the implementation caching all the already read rows in memory?
    Any help would be great,
    Alex

    if and how there are ways to read a Resultset 2 or more times
    forward-only and the data is not completelly cached on the client If the client reads a million rows, how can it read them a second time without either storing them somewhere on the client as in scrollable cursors, or rereading them from the server as in regular cursors. To me this looks like the laws of physics, rather than something that can be changed in a software release.
    In order of preference I would
    1. Not process a million rows on the client.
    2. Use a regular cursor and fetch it twice, the second fetch will be faster as the database already caches as much of it as it can.
    Fetching that much data somewhere is going to take some time anyway, which is why I prefer the first option..

  • Problem with GenericCatalogDAO  JDBC Resultset using parameters not working

    Hello
    I have a problem with Petstore GenericCatalogDAO. java. The problem is the behaviour of the resultset object when retrieving data from the database.Below are two synareos one that
    works (when) hard coded and one that does not work when parameter values passed into the the result set.
    1. The code the WORKS.
    statement = connection.prepareStatement("select a.productid , name, descn from product a, product_details b
    where a.productid = b.productid and locale= 'en_US' and a.catid = 'FISH' order by name"
    ,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    The code that gives me a 'exhausted resultset' error which I think means no results
    String[] parameterValues = new String[] { locale.toString(), categoryID };(For example parameters are 'en_US' and 'FISH')
    statement = connection.prepareStatement("select a.productid , name, descn from product a, product_details b
    where a.productid = b.productid and locale=? and a.catid =? order by name"
    ,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    for (int i = 0; i < parameterValues.length; i++) {
    statement.setString(i + 1, parameterValues[i]);
    resultSet = statement.executeQuery();
    resultSet.absolute(1);
    String s = resultSet.getString(1);
    There is obviously a problem using these named parametevalues with these preparedstatement resultset, Does anybody know anything about this and a fix for it????
    Cheers. Roger

    Which version of PetStore are you using?
    -Larry

  • Problem with JDBC resultset

    Hello everyone:
    I'm using JDBC to connect to SQL Server, normally after executeQuery();, it should return me a opened BaseResultSet in order that i can read datas by stream(next(), getColumn(),etc...) but sometimes it returns a BaseResultSet closed. (I detected it during the debugging by checking the value of the property "closed" in the object returned ), in this case it refused all the following operations with the exceptions "ResultSet has been closed".
    Does that sound normal? How to solve it ?
    Thanks a lot!!!!

    Did you close the underlying Statement or Connection objects? It might come back empty (e.g., next() returns false), but it should not come back already closed.
    - Saish

  • ResultSet problem with a jdbc connection pool implementation

    Hi
    I'm trying to use jdbc connection pool in my java application (js2e 1.4.0_01)
    from the example at http://www.developer.com/tech/article.php/626141
    In my main() code, in addition to JDBCConnection, JDBCConnectionImpl and JDBCPool classes, i use
    JDBCConnection conn;
    conn = new JDBCConnection(dbName);
    // make a statement
    sqlString = "SELECT........."
    ResultSet rs = null;
    rs = conn.sendRequest(sqlString, rs);
    // print result
    while (rs.next()) {
    Unfortunately i get an error like "ResultSet is closed" in the line corresponding to rs.next. The error disappears if i remove the line
    stmt.close();
    in the method sendRequest of the JDBCConnectionImpl class.
    1) Does anybody knows the solution?
    2) How to close all connections?
    Thanks you in advance.

    Hi ,
    You are closing the statement and then trying to use resultset , which is not going to work .So close then statment after using resultset .Ideally the code should be like this
    try {
    conn = // get the connection
    pstmt = conn.prepareStatement(sql);
    rs = pstmt.executeQuery();
    while ( rs.next()){
    // do something
    catch (Exception ex) {
    finally {
    try {
    if (rs != null)
    rs.close();
    if (pstmt != null)
    pstmt.close();
    if(conn!=null )
    conn.close();

Maybe you are looking for

  • Physical Inventory Movement Block not Rest at Storage Location Level

    Hi, We are facing a typical problem in our Production System and the issue is as follows: 1. We have created a Physical Inventory Document for a material with Freeze Book Inventory and Posting Block indicators. 2. We completed the count and entered t

  • How do I copy an art object from one document to another using illustrator API(C  )

    Hi, I'm trying to copy text and graphic elements from one document into another, does anybody has an idea how to do it using Illustrator SDK(C++)? Thanks in advance.

  • Quicktime lockup on installation

    I've been having this same problem since I bought a new ipod in July. Still havent been able to install the Quicktime application and the new Ipod doesnt recognise the old iTunes. I have XP SP3. Intel pentium 4 2.6Ghz. 4Gb RAM. 250GB open on one HDD,

  • Fire tv connection problem

    For some reason my fire to box has stopped connecting to my hub, have turned it on and off, changed channels and even move the box closer to the hub, it connected at first then disconnected and will

  • ADF/UIX

    We are follow this note: http://otn.oracle.com/products/jdev/collateral/papers/10g/ADFBindingPrimer/index.html who they are the correct steps/context to set view to "forwardOnly", due to when I set vo.setForwardOnly(true) an exception is rise (operat