Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in thread "main" java.lang.IllegalArgumentException: Attempted > to write to readonly tuple #2194

Closed
prasanthreddy-git opened this issue Jun 28, 2021 · 4 comments

Comments

@prasanthreddy-git
Copy link

When updating a resultset the second time, after a refresh row causes an exception.

Driver Version: 42.2.11 and above
Java Version: 1.8.0.292
OS Version: CentOS 8
PostgreSQL Version: 12

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

public class RowSet {

public void test () throws SQLException, ClassNotFoundException {
	Class.forName("org.postgresql.Driver");
	Connection connection = DriverManager.getConnection("jdbc:postgresql://192.168.0.125:5432/testdatabase", "postgres", "xxxxxxxxxxxxxxxxxxxxxxxx");
	String sql = "SELECT * FROM accounting_periods where plan_id = 30756 order by start_date";
	ResultSet rs = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE ).executeQuery(sql);
	rs.next();
	rs.updateDate("start_date", Date.valueOf("2020-01-01"));
	rs.updateDate("end_date", Date.valueOf("2020-12-31"));
	rs.updateRow();
	rs.refreshRow();
	rs.updateDate("end_date", Date.valueOf("2020-12-30"));
	rs.updateRow();   // this is where the exception occurs.
	connection.close();		
}

public static void main(String args[]) {		
	try {
		new RowSet().test();
	} catch (SQLException e) {		
		e.printStackTrace();
	} catch (ClassNotFoundException e) {
		e.printStackTrace();
	}
}

}

Exception in thread "main" java.lang.IllegalArgumentException: Attempted to write to readonly tuple
at org.postgresql.core.Tuple.set(Tuple.java:96)
at org.postgresql.jdbc.PgResultSet.updateRowBuffer(PgResultSet.java:1690)
at org.postgresql.jdbc.PgResultSet.updateRow(PgResultSet.java:1384)
at com.nqadmin.test.RowSet.test(RowSet.java:22)
at com.nqadmin.test.RowSet.main(RowSet.java:28)

@prasanthreddy-git
Copy link
Author

If rs.absolute(rownumber) is called after refreshRow() call then the exception does not occur.

@davecramer
Copy link
Member

So, yes, I can replicate this, and will fix it, however you should be aware that refreshRow causes a round trip to the db.

@prasanthreddy-git
Copy link
Author

yes, the intent of the refresh is to get any defaults from database after inserting a row.

@davecramer
Copy link
Member

duplicate of #2193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants