Set JDBC cursor type with Spring - 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.

Related

H2 database corruption on a regular basis

i'm the developper of an open-source application designed for self-hosting. As such, it is used by many people on various systems, OSes, and hardware. It's built using Kotlin and Spring Boot, and uses H2 as the database. The problem i have is that many users are facing database corruption from times to times (it happened to me also a few times).
The corruptions are always of the form:
org.h2.jdbc.JdbcSQLNonTransientException: General error: "java.lang.IllegalStateException: Chunk 20221 not found [1.4.200/9]" [50000-200]
I can't pinpoint any particular reason for those corruptions. The application doesn't use any dangerous H2 options. I couldn't find anything on the web or Stackoverflow that relates to my (imho) mundane use of H2.
I'm using:
Spring Boot 2.2.6.RELEASE
jOOQ 3.13.1 (but i had the same issues before with Hibernate)
H2 1.4.200
The connection string is pretty straightforward:
jdbc:h2:~/.komga/database.h2
The application is doing heavy writes once in a while (during file system scanning), but afterwards it's doing mostly reads.
Would you have suggestions on how to better configure H2 to avoid those issues ?
If your application uses Thread.interrupt() for threads doing calls into embedded database, this is the reason of corruption, don't do this or use the async: filesystem (jdbc:h2:async:…).
If classloader with H2 can be forcibly unloaded (on some application servers, for example) or application is going to be terminated in some abnormal way, you need to close all connections before it or execute the SHUTDOWN command and wait for its completion.
If you try to open the database file with some older version of H2, it can corrupt the file created by a more recent version.
You may run into some bug in H2, so if you can build a standalone test case (Java / JDBC / SQL only, no third-party libraries), you need to fill a new issue on GitHub. You can also try to build H2 from its current sources, there were some changes in the storage backend, but current H2 is very different from 1.4.200 in other aspects and third-partly libraries that you use may be not yet ready to work with it.
You can use the legacy PageStore backend instead of default one by appending ;MV_STORE=FALSE to the JDBC URL when you create your database. This backend uses table-level locks (you need to lock tables in the same order in all your transactions) and doesn't execute commands from different sessions in parallel, but it is more reliable.
You can use a separate H2 Server process; such configuration is usually more reliable than embedded databases, but it works slower.
In any case, with any DBMS, you should create backup copies on regular basis. H2 has BACKUP command for this purpose.

Is Spring Data Jdbc recommended for Oracle 18c?

Is Spring Data JDBC v1.1.5 recommended for Oracle Database and Enterprise Applications? Lot of samples around the net based on Open Source RDBMS (H2 or PostgreSQL). We are using Spring Data JDBC in a Spring Boot Microservice Application, facing following problems.
Force to write custom converters for oracle.sql.TIMESTAMP, oracle.sql.TIMESTAMPTZ and oracle.sql.DATE and oracle.sql.ROWID etc..
Can't type cast oracle.sql.ROWID to java.lang.Number
Identity must not be null after save.
Spring Data JDBC is absolutely recommended for Enterprise Applications.
Not so much for use with Oracle.
Since the necessary resources (database & JDBC driver) weren't available in a form that could be easily used in integration tests on public platforms, Oracle isn't included in regular builds.
Therefore it is likely that one encounters issues when working with Oracle.
Some are already known, for others issues in Jira or even PRs are highly appreciated.

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/

Java JDBC connection pool library choice in 2011/2012?

Which JDBC connection pool library should I use for a new application project (not web application)?
Apache DBCP has enough unresolved issues which are pushed until 2.0 I think.
C3P0 development seems to be stopped.
And both of them looks relatively slow.
Proxool is dead.
DBPool has almost no community (at least I've found no public one - no forums, no mailing lists...)
Apache Tomcat Pool looks to be unusable without Tomcat
I've found SQL Datasources article at Oracle website, but it seems, that it can be applied only to applets running in containers like servlets and web services.
Should I choose BoneCP may be? I don't have any huge requirements. I just need a good and easy to use database connection pool, that is in active development. Library, whose author can respond to bug reports, answer some specific question etc.
BTW, actually, I'm using MySQL only. I've found, that MySQL driver supports DriverManager interface, but I'm unsure if it actually pools connections or not.
You've done good research. I'd say, go ahead with BoneCP. Some years ago I would have suggested c3p0, but it has currently some open and unresolved issues as well. Too bad, actually. The BoneCP author is by the way also active here at SO.
It is possible use Tomcat Connection Pool without Tomcat, it is just a couple of .jars that you can include to any software. I have successfully used Tomcat Connection Pool with Resin and Jetty application servers.
Another alternative is Vibur DBCP. This is a new, concurrent JDBC connection pool based on Java dynamic proxies. It is fast, has concise source code, supports fairness parameter, JDBC Statement caching, long running SQL queries logging, and many other features.
Vibur DBCP is available in the central Maven repo, the website shows the needed Maven dependency, various configuration examples (with Spring, Hibernate 3.x/4.x/5.x), and all configuration options.
Vibur DBCP requires Java 1.7.
Disclaimer: I'm the author of Vibur DBCP.
I know its too late for answer but I just found an interesting link which has given a broader scope to answer most your queries. But at the end HikariCP and BoneCP are much better than other options.

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