1

I have some test code using JDBC to connect to MySQL, PostgreSQL, Oracle, and SQL Server, with only some minor differences between databases. I would like to run this test code as well on DB2. To start with a blank slate, and also test our database creation DDL, the tests start by creating a database (e.g. CREATE DATABASE), and end by deleting that database (e.g. DROP DATABASE).

I read a comment from 2012 saying that, at least on DB2 for Linux, one can't run CREATE DATABASE and DROP DATABASE through JDBC, but only from the command line, which would be a bummer for running my integration tests on DB2. Is there really no way of creating, and then dropping a database through JDBC?

1
  • One thing to keep in mind, a "database" in MySQL or SQL Server is closer to a schema in DB2. Commented Dec 15, 2016 at 18:13

1 Answer 1

1

JDBC is for only SQL. Create database or Drop database is not SQL, and for this reason that statement cannot be executed from JDBC. You can execute DB2 commands via Runtime class, or using JNI to use the DB2 API

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the response. By "Runtime class", are you referring to a Java class/API that can be called from Java code? Where can I find more information about this API? I'd prefer not to use JNI, as this would create more portability, deployment, and configuration complications than I'd like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.