/***************************************************************************** * Title: CreateInformixDB.java * * Description: Demo how to create a database * *************************************************************************** */ import java.sql.*; import java.util.*; public class CreateInformixDB { public static void main(String[] args) { String url = "jdbc:informix-sqli://elara.nvc.cs.vt.edu:8300:informixserver=elara_shm;user=;password="; Connection conn = null; int rc; String cmd=null; String testName = "Create Database"; System.out.println(">>>" + testName + " test."); try { Class.forName("com.informix.jdbc.IfxDriver"); } catch (Exception e) { System.out.println("ERROR: failed to load Informix JDBC driver."); e.printStackTrace(); return; } try { conn = DriverManager.getConnection(url); } catch (SQLException e) { System.out.println("ERROR: failed to connect!"); System.out.println("ERROR: " + e.getMessage()); e.printStackTrace(); return; } // Drop database before starting - ignore errors try { Statement dstmt = conn.createStatement(); dstmt.executeUpdate("drop database testDB"); } catch (SQLException e) { ; } try { Statement stmt = conn.createStatement(); cmd = "create database testDB;"; rc = stmt.executeUpdate(cmd); stmt.close(); } catch (SQLException e) { System.out.println("ERROR: execution failed - statement: " + cmd); System.out.println("ERROR: " + e.getMessage()); e.printStackTrace(); return; } try { conn.close(); } catch (SQLException e) { System.out.println("ERROR: failed to close the connection!"); e.printStackTrace(); return; } System.out.println(">>>End of " + testName + " test."); } }