You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Dominik Jednoralski <tw...@googlemail.com> on 2009/08/17 00:04:44 UTC

Strange SQLException when trying to read existing row

Hi Geeks,

I'm integrating the derby-database into a JAVA-driven web application. I'm
new to derby and I have a problem with the execution of a SELECT-statement.
The returned ResultSet is empty, although the selected row is definitely
stored.

The code below *works*, creates a new table and inserts a dummy row.*
*

   - *CREATE TABLE gaps (gapId int generated by default as identity,
   *MBaseId VARCHAR(256), important INTEGER DEFAULT 0,
   ignore INTEGER DEFAULT 0, data LONG VARCHAR,
   creation TIMESTAMP, lastModified TIMESTAMP)
   - INSERT INTO gaps (data) VALUES ('foo')**

At this position, the row is accessible and everything is fine. Later, when
I want to retrieve this very row via the follwing code, it breaks because
the ResultSet is empty. The methods are both members of the same class and
share the connection and statement, which both are class members.

* ResultSet result = statement.executeQuery("SELECT data "
                        + "FROM gaps WHERE gapId = 1" );

            if (result != null) {

                // breaks with sql-exception: no such row
                String data = result.getString(1);*


Can anyone of you help me with this? I'm pretty confused. Thanks a lot in
advance =)

best

Dominik

Re: Strange SQLException when trying to read existing row

Posted by Sai Pullabhotla <sa...@jmethods.com>.
It might help if you actually post the full source code and the stack
trace of the exception.

Thanks.

Sai Pullabhotla
www.jMethods.com




On Mon, Aug 17, 2009 at 10:26 AM, Dominik
Jednoralski<tw...@googlemail.com> wrote:
> Hi Sai,
>
> many thanks for your response. Actually, I polished the code before
> publishing to the mailing list. My original code at the position of the
> error looked like this
>
> if (result != null) {
>                 if (result.next()) {
>                 // breaks with sql-exception: no such row
>                 String data = result.getString(1);
>
> result.next() at this position always reports an empty ResultSet.
>
> Best
>
> Dominik
>
>
> 2009/8/17 Sai Pullabhotla <sa...@jmethods.com>
>>
>> When a ResultSet is produced, the cursor is positioned before the
>> first row. You must call ResultSet.next() method to move the cursor to
>> the first row and then the ResultSet.getXXX methods for each column.
>> Can you verify/confirm if your code is setup to do this?
>>
>> Thanks.
>>
>> Sai Pullabhotla
>> www.jMethods.com
>>
>>
>>
>>
>> On Sun, Aug 16, 2009 at 5:04 PM, Dominik
>> Jednoralski<tw...@googlemail.com> wrote:
>> > Hi Geeks,
>> >
>> > I'm integrating the derby-database into a JAVA-driven web application.
>> > I'm
>> > new to derby and I have a problem with the execution of a
>> > SELECT-statement.
>> > The returned ResultSet is empty, although the selected row is definitely
>> > stored.
>> >
>> > The code below works, creates a new table and inserts a dummy row.
>> >
>> > CREATE TABLE gaps (gapId int generated by default as identity,
>> > MBaseId VARCHAR(256), important INTEGER DEFAULT 0,
>> > ignore INTEGER DEFAULT 0, data LONG VARCHAR,
>> > creation TIMESTAMP, lastModified TIMESTAMP)
>> > INSERT INTO gaps (data) VALUES ('foo')
>> >
>> > At this position, the row is accessible and everything is fine. Later,
>> > when
>> > I want to retrieve this very row via the follwing code, it breaks
>> > because
>> > the ResultSet is empty. The methods are both members of the same class
>> > and
>> > share the connection and statement, which both are class members.
>> >
>> >  ResultSet result = statement.executeQuery("SELECT data "
>> >                         + "FROM gaps WHERE gapId = 1" );
>> >
>> >             if (result != null) {
>> >
>> >                 // breaks with sql-exception: no such row
>> >                 String data = result.getString(1);
>> >
>> >
>> > Can anyone of you help me with this? I'm pretty confused. Thanks a lot
>> > in
>> > advance =)
>> >
>> > best
>> >
>> > Dominik
>
>

Re: Strange SQLException when trying to read existing row

Posted by Dominik Jednoralski <tw...@googlemail.com>.
Hi Sai,

many thanks for your response. Actually, I polished the code before
publishing to the mailing list. My original code at the position of the
error looked like this

*if (result != null) {
**                if (result.next()) {**
                // breaks with sql-exception: no such row
                String data = result.getString(1);*

result.next() at this position always reports an empty ResultSet.

Best

Dominik


2009/8/17 Sai Pullabhotla <sa...@jmethods.com>

> When a ResultSet is produced, the cursor is positioned before the
> first row. You must call ResultSet.next() method to move the cursor to
> the first row and then the ResultSet.getXXX methods for each column.
> Can you verify/confirm if your code is setup to do this?
>
> Thanks.
>
> Sai Pullabhotla
> www.jMethods.com
>
>
>
>
> On Sun, Aug 16, 2009 at 5:04 PM, Dominik
> Jednoralski<tw...@googlemail.com> wrote:
> > Hi Geeks,
> >
> > I'm integrating the derby-database into a JAVA-driven web application.
> I'm
> > new to derby and I have a problem with the execution of a
> SELECT-statement.
> > The returned ResultSet is empty, although the selected row is definitely
> > stored.
> >
> > The code below works, creates a new table and inserts a dummy row.
> >
> > CREATE TABLE gaps (gapId int generated by default as identity,
> > MBaseId VARCHAR(256), important INTEGER DEFAULT 0,
> > ignore INTEGER DEFAULT 0, data LONG VARCHAR,
> > creation TIMESTAMP, lastModified TIMESTAMP)
> > INSERT INTO gaps (data) VALUES ('foo')
> >
> > At this position, the row is accessible and everything is fine. Later,
> when
> > I want to retrieve this very row via the follwing code, it breaks because
> > the ResultSet is empty. The methods are both members of the same class
> and
> > share the connection and statement, which both are class members.
> >
> >  ResultSet result = statement.executeQuery("SELECT data "
> >                         + "FROM gaps WHERE gapId = 1" );
> >
> >             if (result != null) {
> >
> >                 // breaks with sql-exception: no such row
> >                 String data = result.getString(1);
> >
> >
> > Can anyone of you help me with this? I'm pretty confused. Thanks a lot in
> > advance =)
> >
> > best
> >
> > Dominik
>

Re: Strange SQLException when trying to read existing row

Posted by Sai Pullabhotla <sa...@jmethods.com>.
When a ResultSet is produced, the cursor is positioned before the
first row. You must call ResultSet.next() method to move the cursor to
the first row and then the ResultSet.getXXX methods for each column.
Can you verify/confirm if your code is setup to do this?

Thanks.

Sai Pullabhotla
www.jMethods.com




On Sun, Aug 16, 2009 at 5:04 PM, Dominik
Jednoralski<tw...@googlemail.com> wrote:
> Hi Geeks,
>
> I'm integrating the derby-database into a JAVA-driven web application. I'm
> new to derby and I have a problem with the execution of a SELECT-statement.
> The returned ResultSet is empty, although the selected row is definitely
> stored.
>
> The code below works, creates a new table and inserts a dummy row.
>
> CREATE TABLE gaps (gapId int generated by default as identity,
> MBaseId VARCHAR(256), important INTEGER DEFAULT 0,
> ignore INTEGER DEFAULT 0, data LONG VARCHAR,
> creation TIMESTAMP, lastModified TIMESTAMP)
> INSERT INTO gaps (data) VALUES ('foo')
>
> At this position, the row is accessible and everything is fine. Later, when
> I want to retrieve this very row via the follwing code, it breaks because
> the ResultSet is empty. The methods are both members of the same class and
> share the connection and statement, which both are class members.
>
>  ResultSet result = statement.executeQuery("SELECT data "
>                         + "FROM gaps WHERE gapId = 1" );
>
>             if (result != null) {
>
>                 // breaks with sql-exception: no such row
>                 String data = result.getString(1);
>
>
> Can anyone of you help me with this? I'm pretty confused. Thanks a lot in
> advance =)
>
> best
>
> Dominik