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

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

Related

Set JDBC cursor type with Spring

We have developed a Spring Boot Java application which access a DB2 database.
Now the system has been live for some time, we see the DB2 database crash every few weeks, which has caused us to review what cursor settings we have used.
This is where I have struggled - I just cant seem to find a way to influence the JDBC cursor types through Spring. And I worry that we may now need to rewrite the application with direct JDBC calls in order to be able to influence the cursor settings.
I am not a spring developer but have worked extensively with JDBC over the years which is why I have been asked to look at this.

Connect to existing hsqldb instance in IDE

I am learning Spring Boot using open-source projects and have stumbled upon their demo project — PetClinic. It has two possible databases configured: MySQL & HSQLDB, it uses the latter by default.
So I was able to launch the project look at it on localhost and can see that the DB (HSQLDB) is being populated but I was unable to set up a connection through the Intellij IDEA because the project does not specify the path that allows to see the contents of this in-memory DB.
Can anyone please tell me, what am I missing in the process of establishing the connection to HSQLDB here?
Thanks!
You can't connect to an in-memory instance of HSQLDB from another process.
The main drawback [of in-memory mode] is that it is not possible by default to connect to
the database from outside your application. As a result you cannot
check the contents of the database with external tools such as
Database Manager while your application is running.
If you want to do this, you need to run HSQL as a server. More details about how to run it in server mode can be found here.

Does a java application that uses JDBC 4 driver type requires db2 binding

Our java applications will access legacy mainframe db2 databases.
I remember in my previous projects, C++ applications required db2 binding before deployment.
In current projects, all mainframe applications, Cobol packages are also required to do db2 binding.
Does a java application that uses jdbc4 driver needs db2 binding too?
If you are using standard JDBC you are creating dynamic SQL (PrepareStatement) that do not requires binding in DB2 side.
However, if you use SQLj, you will need to 'precompile' that code to generate you .java files and another file to bind in the database.
It does not matter if you are connecting to a mainframe (system z or i) or to a DB2 LUW. The concept is the same for all platforms as DB2 is DB2.
SQLj is not very popular, however is very powerful to tune your queries and improve the data access, however, as you used to do in C, the code has to be developped in more phases, and you have to rebind each time the access plan has to be modified (new statisques, security, etc.)
SQLj is very easy to use from Data Studio, and SQLj from DB2 is not exactly the same from Oracle.
The JDBC type IV driver, supplied by IBM, will handle everything you need to do.
The driver maps Java objects into DB2 appropriately.
I don't know what "binding" means in this context. Java is not C++.
If your DB2 version supports Dynamic Statement Caching and enabled (consult your DBA’s), you can use JDBC Type-4 driver to access mainframe DB2 database (use prepare statement) without binding.
DB2 will generate access paths and store it in first request into cache. Otherwise, you need use SQLJ like technologies and bind them.

What is difference between oracle.jdbc.xa.client.OracleXADataSource and oracle.jdbc.pool.OracleDataSource

I am trying to understand the difference between XA vs Non XA JDBC datasource. Also how do I know which type and version of JDBC dtriver is used. I am currently on 10.3 weblogic and trying some tet to kill long running queries using setQueryTimeout, which isnt seem to be reliable with OracleXADataSource as it is only working the first time and not always.
Sorry for this basic question but I am new to Weblogic Datasource configuration
Thanks
XA jdbc drivers are used to implement two-phase commit, meaning the two remote resources are part of the same transaction. Java specifies an implementation of this via JTA. A good reading is e.g. http://www.javaworld.com/javaworld/jw-07-2000/jw-0714-transaction.html; if you google for 'xa jdbc driver' you'll find plenty more info.
You should not use the XA driver if not necessary. I remember reading that there are some problems with them.
To identify JDBC driver your WLS is using, go to the <domain_dir>/config/jdbc and open the data souce file, check the driver-name value in the file.
To identify the Driver version, check from which .jar is the driver being loaded (run the WLS with -verbose:class)- the name of the jar will contain the version number. Also, you can use java -jar my-jdbc-file.jar which will print the driver version. The OJDBC drivers are usually stored in a file named ojdbc6.jar or ojdbc7.jar, etc.

SQL logging in Websphere 6.1

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

Resources