2017  Kodetalk | Feedback | Privacy Policy | Terms | About

Java jdbc - how to execute a statement strictly read only

How to restrict or sure the query does not modify the database? Is it possible to execute a query read only?

According to javadoc JDBC supports read-only connections by calling Connection.setReadOnly(true).

You can individually set connections to be read-only:

public Connection getReadOnlyConnection() {
    final Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","username","password");
    return conn;

Answer is