Thread: UPDATE with JDBC fail

UPDATE with JDBC fail

From
Jose.Silva@isotrol.com
Date:
Hi, my name is J.A. Silva
I'm a worker of Isotrol (Spain).
I'm developing a tool for modify values in a PostGreSQL database.
The tool only have to modify some tables with a random value.

The code that do this is ...
private void refrescaTablaDatos()
{
    String sql = "";
    String molino;
    ResultSet rs = null;
    int i = 0;

    try
    {
        // select the primary keys of the items to modify
        sql = "SELECT DISTINCT id FROM datos;";
        rs = this.con.executeSQL(sql);

        // modify one per one all the items ...
        while(rs.next())
        {
            molino = rs.getString(1);

            sql = "UPDATE datos SET valor = " +
                   (float)(100*Math.random()) +
                ", timestamp = now() WHERE id = " +
                molino + ";";

            this.con.executeSQL(sql);
            i = i + this.con.getFilasAfectadas();
        }
    }
    catch(Exception e)
    {
        e.toString();
    }
}

The function is very simple ... but it does not work.
The database doen not change its values.

The select query works perfectly but the update funtion does not do anything.

I hope that you can help me. I will be expecting your answer.

The PosrGre version that I use is 7.1. and the JDBC driver that I use is
the driver that you can get of Postgre's webpage.

My english level is not good, I hope that you can understand this mail.

Thanks for all and good bye

Re: UPDATE with JDBC fail

From
Kris Jurka
Date:

On Thu, 5 Aug 2004 Jose.Silva@isotrol.com wrote:

> The function is very simple ... but it does not work.
> The database doen not change its values.
>
> The select query works perfectly but the update funtion does not do anything.
>

Any chance you have autocommit set to false and are not issuing a commit
at the end of your code?


Kris Jurka

Re: UPDATE with JDBC fail

From
Oliver Jowett
Date:
Jose.Silva@isotrol.com wrote:

>         rs = this.con.executeSQL(sql);

There is no executeSQL() method on java.sql.Connection.

There might be one down in the guts of the driver implementation
classes, but you certainly shouldn't be using that.

What is the 'con' object, really? We need to see how the driver-level
objects are used to be of any help.

-O

Re: UPDATE with JDBC fail

From
Oliver Jowett
Date:
Jose.Silva@isotrol.com wrote:

> The PosrGre version that I use is 7.1. and the JDBC driver that I use is
> the driver that you can get of Postgre's webpage.

Also, I've stopped testing against 7.1 (and I think Kris has too) --
it's getting very old now. I think that at least
setTransactionIsolation() will not work correctly with the current
driver against a 7.1 server. I'd strongly recommend you upgrade to a
more recent server if you can, not only for a tested driver but also for
any number of server-side bugfixes..

-O

Re: UPDATE with JDBC fail

From
Kris Jurka
Date:

On Fri, 6 Aug 2004, Oliver Jowett wrote:

> Also, I've stopped testing against 7.1 (and I think Kris has too) --
> it's getting very old now. I think that at least
> setTransactionIsolation() will not work correctly with the current
> driver against a 7.1 server.

I only run specific tests against old versions when modifying something in
that area because the regression tests haven't run successfully
against 7.1 in the time I've been working on the driver.  If we know the
driver doesn't work against old server versions we should refuse to
connect or issue some kind of error message.  Are there things other than
transaction isolation you'd like me to test against 7.0 or 7.1?

Kris Jurka

Re: UPDATE with JDBC fail

From
Oliver Jowett
Date:
Kris Jurka wrote:

> I only run specific tests against old versions when modifying something in
> that area because the regression tests haven't run successfully
> against 7.1 in the time I've been working on the driver.  If we know the
> driver doesn't work against old server versions we should refuse to
> connect or issue some kind of error message.  Are there things other than
> transaction isolation you'd like me to test against 7.0 or 7.1?

Transaction isolation was the only thing that springs to mind (when I
rearranged the protocol code, the per-transaction setting of isolation
level for older servers got thrown out), but there may well be other stuff.

I think we should either fix the regression tests to work against
7.0/7.1, or drop support for those versions entirely and refuse to
connect. I know which is easier :)

-O