Intercept SQL's in a custom JDBC

3

Is it possible to create a custom implementation based on JDBC to intercept all sql's executed in the application?

I did not find anything very concrete about this in Google, I did a simple test just inheriting the interface of the driver I wanted and with that I made the connection to the database and the querys execute perfectly but I still have not figured out how to intercept what was executed, if anyone has any idea or example that can help you decipher the puzzle, or what is the best way to do it, or if it is impossible.

Here is an example of the simple interface:

package br.com.jdbc;
import org.firebirdsql.jdbc.FirebirdDriver;

public interface FRDriver extends FirebirdDriver {


}

Test file:

package br.com.jdbc;

import java.sql.DriverManager;

import org.firebirdsql.jdbc.FBConnection;

public class Teste {
    public static void main(String[] args) throws Exception {
        Class.forName("br.com.jdbc.FRDriver");
        System.out.println("Connecting to database...");

        FBConnection conn = (FBConnection) DriverManager.getConnection("jdbc:firebirdsql:localhost:BANCOTESTE?encoding=WIN1252","SYSDBA","masterkey");
        System.out.println("CONEXAO OK");
        conn.close();
        System.out.println("CONEXAO ENCERRADA");
    }
}
    
asked by anonymous 01.04.2016 / 02:45

0 answers