2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

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?
userimage

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");
    conn.setReadOnly(true);
    return conn;
}

Answer is