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