0

I've an error and i can't figure it out why is this occurring. I search over the internet but i've found nothing conclundent. Can you help me please ? What i'm doing wrong ? How it should be written this code so that this issue will not occur anymore ?

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.RowSetWriter;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;


public class Testing {


    void example() {
        try {

              Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String url = "jdbc:sqlserver://localhost:1433;databaseName=Movies; integratedSecurity=true";
            Connection connect = DriverManager.getConnection(url);
            Statement s = connect.createStatement();
            ResultSet rs = s.executeQuery("select filmname from tblFilm where filmRuntimeMinutes <100");

            CachedRowSet cached = RowSetProvider.newFactory().createCachedRowSet();
            cached.populate(rs); // populam cached row set cu datele obtinute din ResultSet
            cached.moveToInsertRow(); //mutam cursorul pentru a permite modificari
            cached.updateString(1, "Ionut Asaftei"); //aplicam modificarea pe coloana dorita
            cached.insertRow(); //are ca efect introducerea noii inregistrari doar in row set (nu se conecteaza inca la baza de date
            cached.moveToCurrentRow(); // muta cursorul pe ultima pozitie retinuta /amintita / curenta
            cached.setTableName("tblFilm");
            cached.acceptChanges(connect); //modificarile sunt salvate pe server




        while(cached.next()) {
            System.out.println(cached.getString(1));
        }


    }catch(ClassNotFoundException | SQLException e) {
        e.printStackTrace();

    }


    }




    public static void main(String[] args) {

                Testing obj = new Testing();
                obj.example();
    }

    }

Exception:

javax.sql.rowset.spi.SyncProviderException: 1 conflicts while synchronizing
at com.sun.rowset.internal.CachedRowSetWriter.writeData(Unknown Source)
at com.sun.rowset.CachedRowSetImpl.acceptChanges(Unknown Source)
at com.sun.rowset.CachedRowSetImpl.acceptChanges(Unknown Source)
at Testing.example(Testing.java:31) at Testing.main(Testing.java:55) 
user207421
  • 305,947
  • 44
  • 307
  • 483
  • After doing printStackTrace(), this is what i'm getting: javax.sql.rowset.spi.SyncProviderException: 1 conflicts while synchronizing at com.sun.rowset.internal.CachedRowSetWriter.writeData(Unknown Source) at com.sun.rowset.CachedRowSetImpl.acceptChanges(Unknown Source) at com.sun.rowset.CachedRowSetImpl.acceptChanges(Unknown Source) at Testing.example(Testing.java:31) at Testing.main(Testing.java:55) – Ionutz Asaftei Sep 27 '15 at 20:30

1 Answers1

0

I also faced the similar problem when I was using CachedRowSet to manage data retrieved from MySql database. From that I know two situation for which this problem can occur:- (1) When we update the primary key field in database table and specially when inserting the same value which is already present in some raw in table, because we can not insert same primary key multiple time in the table. (2) When schema doesn't match like the field which are modifying is of size 10 char and we are trying to write 11~20 char value

Could you check above points ? if you found some other problem then please share because It could be any similar confict between the data your are trying to saving and data which are acceptable as per database table

If you are still facing problem please describe your tblFilm database table.