Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java / mySQL error

1 view
Skip to first unread message

ice

unread,
May 21, 2003, 7:48:42 AM5/21/03
to
Hello

I am reusing code that did what was required for an Oracle 9i db. Now
I have to use mySQL and I am getting an error - but Ihave no idea why.
Can any one shed some light on what this error means and I how i can
fix it.

I have included a portion of the code below that I think is generating
the error and the top part of the error message.

The strange thing is that the data is actually entered into the
Database.

Thank you for taking the time to help a newbie out :)

Callum

Code generating error:
///////////// code snippit start ///////////////////////////////////
try {
databaseConnection = new PooledDatabaseConnection();
PreparedStatement pStmt =
databaseConnection.prepareStatement(
"select * from " + TABLE_USER + " where 1=0",
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pStmt.executeQuery();
if (rs != null) {
rs.moveToInsertRow();
rs.updateInt(COL_AC_NUMBER,ac_number);
rs.updateString(COL_USERNAME,username);
rs.updateString(COL_PASSWORD,password);
rs.updateString(COL_U_STATUS,u_status);
rs.updateInt(COL_U_NUMBER,u_number);
rs.updateString(COL_TITLE,title);
rs.updateString(COL_FORENAME,forename);
rs.updateString(COL_SURNAME,surname);
rs.updateString(COL_TELEPHONE,phone);
rs.updateString(COL_EMAIL,email);
rs.updateString(COL_DEPARTMENT,department);
rs.insertRow();

////////////////// i think it is getting upset here//////////////////
userid = rs.getInt(COL_USERID);

// the COL_USERID is auto incremented in the DB

}
else {
throw new SQLException(//error msg);
}
rs.close();
pStmt.close();
databaseConnection.commit();
databaseConnection.returnConnection();
}
catch (SQLException sqle) {
cat.error(
"Account.java: createRow: Unable to create new row,
SQL failure", sqle);
}
catch (DatabaseException sde) {
////error msg
}
///////////// code snippit end ///////////////////////////////////

Brief error as follows:

2003-05-21 12:35:52,930 ERROR [main] ddl.Account (
User.java:406) - Account.java: createRow: Unable to create new
row, SQL failure
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:3533)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1718)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1232)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1268)
at com.inrs.ddl.User.createRow(User.java:394)
at com.inrs.ddl.User.update(User.java:282)
[more error stuff removed]

Mark Matthews

unread,
May 21, 2003, 9:42:13 AM5/21/03
to ice
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

ice wrote:

> Hello
>
> I am reusing code that did what was required for an Oracle 9i db. Now
> I have to use mySQL and I am getting an error - but Ihave no idea why.
> Can any one shed some light on what this error means and I how i can
> fix it.
>
> I have included a portion of the code below that I think is generating
> the error and the top part of the error message.
>
> The strange thing is that the data is actually entered into the
> Database.
>
> Thank you for taking the time to help a newbie out :)
>
> Callum
>
> Code generating error:
> ///////////// code snippit start ///////////////////////////////////
> try {
> databaseConnection = new PooledDatabaseConnection();
> PreparedStatement pStmt =
> databaseConnection.prepareStatement(
> "select * from " + TABLE_USER + " where 1=0",
> ResultSet.TYPE_SCROLL_SENSITIVE,
> ResultSet.CONCUR_UPDATABLE);
> ResultSet rs = pStmt.executeQuery();
> if (rs != null) {
> rs.moveToInsertRow();

[snip]

> rs.insertRow();
>
> ////////////////// i think it is getting upset here//////////////////
> userid = rs.getInt(COL_USERID);
>
> // the COL_USERID is auto incremented in the DB

[snip]


> ///////////// code snippit end ///////////////////////////////////
>
> Brief error as follows:
>
> 2003-05-21 12:35:52,930 ERROR [main] ddl.Account (
> User.java:406) - Account.java: createRow: Unable to create new
> row, SQL failure
> java.sql.SQLException: Before start of result set
> at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:3533)
> at com.mysql.jdbc.ResultSet.getString(ResultSet.java:1718)
> at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1232)
> at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1268)
> at com.inrs.ddl.User.createRow(User.java:394)
> at com.inrs.ddl.User.update(User.java:282)
> [more error stuff removed]

The JDBC spec unfortunately doesn't say where the 'cursor' should end up
after calling insertRow(), only that you can return to the row that the
result set was on 'previously' with moveToCurrentRow(). With MySQL, the
behavior is that the cursor is 'left' on the current row (if there was
any) after insertRow(), but rows created by insertRow() are stored at
the _end_ of the result set, so you can move to last(), and then do your
read. Because of the way your code is structured, you have not moved the
cursor to a valid row, so the cursor remains before the start of the
result set, thus leading to the exception.

-Mark

- --
For technical support contracts, visit https://order.mysql.com/?ref=mmma

__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mark Matthews <ma...@mysql.com>
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, SW Dev. Manager - J2EE/Windows
/_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
<___/ www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+y4I1tvXNTca6JD8RAn/SAJwLXr2AUP/tOns76s7aBOBIwdDs0QCeKLIX
3xzCyvGvBoTqan7mhwfIqD4=
=/wuZ
-----END PGP SIGNATURE-----

ice

unread,
May 21, 2003, 5:20:48 PM5/21/03
to
Thank you

that sorted it out fine. Thank you for taking the time to teach me :)

Cheers
Callum

0 new messages