Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Create DB2 database

843859Jun 17 2008 — edited Nov 20 2014
Hi

I want to create a database in DB2 dynamically through java code and jdbc type 4 driver for DB2. I used the following code:
import java.sql.*;
import java.io.*;

public class DBTry
{
	public static void main(String s[]) throws IOException, SQLException
	{
		Connection conCopyTo = null;
		try
		{
			//retreive connection for DB2
			String url = "jdbc:db2://localhost:50000/default";
			String userId = "sajal";
			String pwd = "admin";
			Class.forName("com.ibm.db2.jcc.DB2Driver");
			conCopyTo = DriverManager.getConnection(url, userId, pwd);		
			System.out.println("ConvertAcc2DB2:ConCopyTo:"+conCopyTo);
		}
		catch(Exception e)
		{
			System.out.println(e);	
		}
		
		try
		{
			PreparedStatement psc=conCopyTo.prepareStatement("Create database DBtry");
			int updatec=psc.executeUpdate();
			System.out.println("Database Created!updatec"+updatec);
		}
		catch(Exception e)	
		{
			System.out.println("ConvertAcc2DB2:createDatabase:PreparedStatementException:"+e);
		}
	}
}
But the output shows following exception:
ConvertAcc2DB2:ConCopyTo:com.ibm.db2.jcc.b.b@19134f4
ConvertAcc2DB2:createDatabase:PreparedStatementException:com.ibm.db2.jcc.c.SqlEx
ception: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: database;Creat
e ;TABLESPACE
Can some one please give me a working code for this problem

Thanks!
Ashish
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 15 2008
Added on Jun 17 2008
1 comment
120 views