SQL logging in Websphere 6.1 - jdbc

I am looking for a tool that Logs SQL statemetns fired in the application as I use the application.
I found p6spy. But there is an issue with that. It doesnt seem to be compatible with XA Datasources.
Is there a way to make p6spy work on Websphere 6.1 OR is there an alternative to p6spy ?
Also, if anyone has any AspectJ code that intercepts the PreparedStatment object and dumps the SQL, that would also be great.

It is not mandatory for the JDBC drivers to implement a feature to be able to extract / print out the SQL statements. To be honest, I would do this in database. All reasonable database products can log in detail everything that comes in. Also, you can at the same time get further information like execution plans and their impact on the server.

It does depend on the way that you are accessing the database. If you are using Hibernate then you can make that spit out its SQL, if you are accessing the datasource through WAS then you can use the trace service. Set the trace to something like:
=info: com.ibm.websphere.rsadapter.=detail
And see what you get out of it.

I seem to remember there being some parameter you can add to your jdbc url configuration, and/or the connection. Can't remember the details.

You shold change trace level into jdbc driver.
If you using DB2 then change custom properties for data source
if you using Oracle then change driver on the ojbdc6_g.jar and change JVM properties

Related

How to use p6spy for standalone application that limits its JDBC drivers?

I have a standalone 3rd party application working with Oracle database and I need to troubleshoot its DB queries. And I don't have access to its source code (nor desire to decompile it :-) ).
Its DB connection configuration has several separate parameters:
Driver: oracle.jdbc.OracleDriver
JDBC URL: jdbc:oracle:thin:#localhost:1521:orcl
User name & password
But I can't change driver as application is checking for a list of supported drivers and just refuse to start if I put com.p6spy.engine.spy.P6SpyDriver into the driver parameter.
So can p6spy still be used in this case? If not, is there any other way to trace application DB access from application's end (I'm aware of Oracle tracing, that would be my next step if this won't work)?
Many thanks!
You can use P6Spy in Datasource way

Old style outer join (+) cannot be used with ANSI joins, Oracle Database Error Code ORA-25156

Why I get this error even though i specified the hibernate.dialect as OracleDialect. If you recommend to use oracle10gDialect or Oracle9iDialect please explain, cause Hibernate can find the Dialect using JDBC meta data when it connect to the db in very first time. Correct me if i'm wrong.
I believe your problem is to find the correct dialect. But I believe this is part of the configuration. This is not a programming problem, This is a configuration strategy that you used to manipulate or use of configuration.
you can externalize the configuration with multiple profiles such as dev, UAT, PROD which is based on the environment. Then your CICD
the pipeline will pick the correct profile which has the correct dialect according to the deployed environment.
Or you can add default dialect and override the properties based on
the environment in which the application is deployed.
The reason is application is the component where looking for the database.
or check this post if you wanted to do programmatically ( I haven't try this) :
Is there a way to detect SQL Dialect without knowing the database type?
Also please read the driver specification and JPA dialect usage. some databases expect exact versions of dialect to support full functionality.

Embed database in spring project with hibernate

In my previous spring projects, I always use hibernate+postgresql to store the data. I rencently start to use spring-boot, and I am looking for a database system which allow me embed it in my project, without be required the installation of a external DBMS.
I try use SQLite, but in my searches I found some afirmations Hibernate isn't compatible with SQLite.
Anyone knows if this is possible and could point me a solution?
We've successfuly used HSQLDB with Hibernate for ages.
This is actually super cool for sales, you can demonstrate a working application on (potential) customers machine with the embedded HSQLDB database. And still be able to switch to "the real thing" later on.
See also this:
Does Hibernate Fully Support SQLite
and this:
https://code.google.com/p/hibernate-sqlite/

custom JDBC driver for SAP Business Objects

I'm writting custom JDBC driver for my datasource. I'd like to use it with Business Objects product from SAP. My driver works fine in Squirell SQL, but when installed in Business Objects (specifically Universe Designer) I'm unable to fetch table contents. I've enabled TRACE for whole Business Objects instance and the problem's log looks like this:
dictionary_thread::Columns : CS:Unexpected behavior
com.businessobjects.connectionserver.RDBMSDictionary}.Columns: [com.sap.connectivity.cs.core.CSError: Unexpected behavior
As for debugging my JDBC driver, I've been using log4jdbc as well as custom logging of method calls and return values (via aspects) and I don't see any errors, exceptions coming from my driver.
Perhaps someone knows a solution for this, or knows how to debug this further?
It seems obvious that my driver is not fully JDBC specs comformant, so any Test Suite which could analyze errors in my driver would also be of use.
The JDBC API Test Suite 1.3.1 is quite outdated but it may help you diagnose your issue, at least for JDBC 2.0 API: Download is no longer available, remains an old Documentation
According to JSR221 for JDBC4 you may ask for JavaSE TCK (JCK) sources at no charge but you have to follow this process. You will have to accept OpenJDK TCK license.

How does P6SPY work?

Pretty much everything in the question. I just discovered p6spy in association with hibernate which is really cool to see the actual sql queries, though I'm quite baffled on how it works.
So how does it work?
the basic idea on p6spy goes like this:
depending if you go for Datasource or for JDBC driver in your code,
what you do is instead of referring the real ones, you specify p6spy
specific ones: com.p6spy.engine.spy.P6SpyDriver or com.p6spy.engine.spy.P6DataSource respectively (for full documentation, see: p6spy.readthedocs.io/en/latest/configandusage.html).
afterwards you configure the real ones in your spy.properties file (using realdriver or realdatasource properties respectively)
depending on the configuration you can achieve the logging of sql statements (using com.p6spy.engine.logging.P6LogFactory)
so to answer your question, the idea is that all the jdbc calls (statements execution, transaction related stuff) will be wrapped (proxied) by p6spy and depending on your configuration, these can be logged via the file logger (using appender=com.p6spy.engine.logging.appender.FileLogger), stdout logger (using appender=com.p6spy.engine.logging.appender.StdoutLogger) or log4j logger (using: appender=com.p6spy.engine.logging.appender.Log4jLogger)
If interested in more details, feel free to ask, or check the project itself on: https://github.com/p6spy/p6spy

Resources