thanks for reply.
but i want to create database dynamically through jdbc .
in java to get connected we have to enter database name in getconnection() method.
[ Connection con = DriverManager.getConnection("jdbc:postgresql://IpAddress:5432/" + databasename, dbusername, dbpassword); ]
but sice we don't have any database how to? & where to get connected?
how to create database at run time??
prepare a class name and do the follow code
//public final static String DRIVER = "com.mysql.jdbc.Driver";
//public final static String URL = "jdbc:mysql://localhost/IA";
//public final static String USER = "";
//public final static String PASSWORD = "";
private static Properties dbprops = new Properties();
private static Driver myDriver = null;
private static Connection connection = null;
private static Statement statement1 = null;
public static void init() {
dbprops.put("user", USER);
dbprops.put("password", PASSWORD);
try
{
myDriver = (Driver)Class.forName(DRIVER).newInstance();
connection = DriverManager.getConnection(URL, dbprops);
try
{
Statement st = connection.createStatement();
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String database = DATABASENAME; // "nlshriraam";//bf.readLine();
st.executeUpdate("CREATE DATABASE "+database);
}
catch (SQLException s)
{
}
}
catch (Exception e)
{
}
return;
}
hope this work
regards
NLShriraam