The following bug has been logged online:

Bug reference:      1005
Logged by:          Lars Tetzlaff
Email address:      [EMAIL PROTECTED]
PostgreSQL version: 7.4
Operating system:   linux 2.4.23 i686
Description:        JDBC cancelRowUpdates() sets column values to null
Details: 

this sequence sets all but "plz" and "kategorie" to null, "kategorie" is changed to 0

  rs.first();
  rs.updateInt( "plz", 99999 );
  rs.cancelRowUpdates();
  rs.updateInt( "plz", 66666 );
  rs.updateRow();
  rs.beforeFirst();

Output before update:
    
  Kunde Lars Tetzlaff
  PLZ/Ort 51702 Bergneustadt
  Straße Bahnhofstr. 32 E
  Kategorie 1


Output after Update

 Kunde null
 PLZ/Ort 66666 null
 Straße null
 Kategorie 0

If i comment out the second updateInt, the data is OK.


java version "1.4.2_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_02-b03)
Java HotSpot(TM) Client VM (build 1.4.2_02-b03, mixed mode)


Table:

create table kunde
(
        name varchar( 30 ) not null primary key,
        plz integer,
        ort varchar(30),
        strasse varchar( 30 ),
        kategorie integer not null
);

insert into kunde values ( 'Lars Tetzlaff', 51702, 'Bergneustadt', 'Bahnhofstr. 32 E', 
1 );



Programm:

import java.sql.*;

public class connect
{
    public static void main( String argv[] )
    {
        try {
            
            //Class.forName("org.postgresql.Driver");
            Connection db = DriverManager.getConnection( "jdbc:postgresql:tetzlaff",
                                                         "tetzlaff", "");

            db.setAutoCommit( false );
            
//          PreparedStatement pst = db.prepareStatement("insert into kunde values ( ?, 
" +
//                            "?, ?, ?, ? )");
            
//          pst.setString( 1, "Thomas Friese" );
//          pst.setInt( 2, 51580 );
//          pst.setString( 3, "Reichshof-Eckenhagen" );
//          pst.setString( 4, "Landwehrstr. 7" );
//          pst.setInt( 5, 3 );
                
//          pst.executeUpdate();
            
            Statement st = db.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE,
                                               ResultSet.CONCUR_UPDATABLE );
            
            ResultSet rs = st.executeQuery("SELECT * FROM kunde");

            if( rs.isBeforeFirst() ) {
                System.out.println( "Alles klar" );
            }
            else{
                System.out.println( "Wo bin ich denn?" );
            }
                        
            while (rs.next()) {
                //System.out.print("Column 1 returned ");
                System.out.println( "Kunde " + rs.getString(1) 
                                    + "\nPLZ/Ort " 
                                    + rs.getInt(2) + " " + rs.getString(3)
                                    + "\nStraße " +rs.getString( "STRASSE" ) 
                                    + "\nKategorie " + rs.getInt( "kategorie" )
                                    );
            }

            rs.first();
            rs.updateInt( "plz", 99999 );
            rs.cancelRowUpdates();
            rs.updateInt( "plz", 66666 );
            rs.updateRow();
            rs.beforeFirst();
            
            while (rs.next()) {
                //System.out.print("Column 1 returned ");
                System.out.println( "Kunde " + rs.getString(1) 
                                    + "\nPLZ/Ort " 
                                    + rs.getInt(2) + " " + rs.getString(3)
                                    + "\nStraße " +rs.getString( "STRASSE" )
                                    + "\nKategorie " + rs.getInt( "kategorie" )
                                    );
            }

            rs.close();
            st.close();
        }
        catch( Exception ex ){
            System.out.println( "Exception" + ex );
        }
        
    }
}


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faqs/FAQ.html

Reply via email to