JDBC Update Problems using PostgreSQL


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: JDBC Update Problems using PostgreSQL

  1. #1
    John McLaughlin Guest

    JDBC Update Problems using PostgreSQL

    I am doing some first tinkering with JDBC and PostgreSQL and I am stumped on
    something.

    I have a simple Java program that queries a table on the PostgreSQL
    workstation successfully. I can iterate through the rows and display them.
    However, when I try to update a value, like using:
    ResultSet rs;
    ...
    rs.updateInt("columnName", newIntVal);

    The rs.updateInt() seems to succeed (no exceptions thrown), but the database
    never gets changed. I am using JBuilder 4, and I *can* make changes to the
    DB using the Data Explorer tool. So, the jdbc driver appears to be working.

    FYI, my connection logic starts as follows:
    ...
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection(
    "jdbcdbcostgresql", "myusername", "mypassword");
    stmt = conn.createStatement(
    ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_UPDATABLE);
    res = stmt.executeQuery("SELECT * FROM customer FOR UPDATE");
    ...

    Any ideas?

    --
    John McLaughlin
    _______________________
    johnm@oei.com





  2. #2
    Paul Clapham Guest

    Re: JDBC Update Problems using PostgreSQL

    The updateInt() method does succeed in what it is supposed to do, namely
    updating the ResultSet. However if you want to propagate those changes to
    the database, you need to call the updateRow() or insertRow() method.

    PC2

    "John McLaughlin" <johnm@oei.com> wrote in message
    news:3bd05cd2@news.devx.com...
    > I am doing some first tinkering with JDBC and PostgreSQL and I am stumped

    on
    > something.
    >
    > I have a simple Java program that queries a table on the PostgreSQL
    > workstation successfully. I can iterate through the rows and display

    them.
    > However, when I try to update a value, like using:
    > ResultSet rs;
    > ...
    > rs.updateInt("columnName", newIntVal);
    >
    > The rs.updateInt() seems to succeed (no exceptions thrown), but the

    database
    > never gets changed. I am using JBuilder 4, and I *can* make changes to

    the
    > DB using the Data Explorer tool. So, the jdbc driver appears to be

    working.
    >
    > FYI, my connection logic starts as follows:
    > ...
    > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    > conn = DriverManager.getConnection(
    > "jdbcdbcostgresql", "myusername", "mypassword");
    > stmt = conn.createStatement(
    > ResultSet.TYPE_SCROLL_SENSITIVE,
    > ResultSet.CONCUR_UPDATABLE);
    > res = stmt.executeQuery("SELECT * FROM customer FOR UPDATE");
    > ...
    >
    > Any ideas?
    >
    > --
    > John McLaughlin
    > _______________________
    > johnm@oei.com
    >
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center