Skip Headers

# Logging SQL

Previous

Next

In a relational project, TopLink accesses the database using SQL strings that it generates internally. This feature enables applications to use the session methods or query objects without having to perform their own SQL translation.

If, for debugging purposes, you want to review a record of the SQL that is sent to the database, set the session log level to `oracle.toplink.logging.SessionLog.FINE`–the session will log all executed SQL to the session log.

Example: Configuring the Log Destination shows how to configure the log destination using the `setLog()` method on the session.

Configuring the Log Destination

    private static SessionEventListener buildListener() {
        return new SessionEventAdapter() {
            public void preLogin(SessionEvent event) {
                File file = new
                File("C:\\oracle\\904\\toplink\\examples\\jdev\\2-TierEmployee\\toplink.log");
            try {
                System.out.println("FILE: " + file.getAbsolutePath());
                FileWriter writer = new FileWriter(file);
                event.getSession().setLog(writer);
                } catch (IOException ioe) {
                ioe.printStackTrace();
                throw new RuntimeException("Failed to setup logging to: " + file.getAbsolutePath());            }
            }
        };
    }