I want to create a db2 database programmatically through jdbc, but i dont know how to do it.
classname = "com.ibm.db2.jcc.DB2Driver";
constring = "jdbc:db2://localhost:50000/";
con = DriverManager.getConnection(constring,"myusr","mypwd");
stmt = con.createStatement();
stmt.executeUpdate("CREATE DATABASE test");
This does not allow me to create a new database stating the reason that my constring is not valid. But in a similar fashion i am able to create database for the mysql.
Pinned topic Create Db2 database through jdbc
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
Updated on 2013-04-02T12:10:16Z at 2013-04-02T12:10:16Z by SystemAdmin
SystemAdmin 110000D4XK17917 Posts
Re: Create Db2 database through jdbc2013-04-02T12:10:16ZThis is the accepted answer. This is the accepted answer.Hi
Actually, you cannot create databases via JDBC, you need to do that via another way, for example via JNI invoking the DB2 API (http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.apdv.api.doc/doc/r0001446.html) or CLI.
The code provided does not work to create a database, you have to change it completly. In order to create a database, it is necessary to attach to an exisiting instance in the server. You cannot be connected to a database, when creating a new one, but JDBC only works with an active connection. The Create Database statement is not SQL, so you cannot use it in a Java SQL Statement.
You can also create the database with the help of the Data Server Client (Runtime), that provides a set of commands that allows you to create the database. You call them from Java via Runtime.exec, but remember to have the DB2 environment loaded and the instance cataloged with the remote server (if any)
MySQL allows you to do many things, even if they are conceptually wrong.