Skip to content

Instantly share code, notes, and snippets.

@adrianhsieh
Created September 22, 2012 19:28
Show Gist options
  • Select an option

  • Save adrianhsieh/3767518 to your computer and use it in GitHub Desktop.

Select an option

Save adrianhsieh/3767518 to your computer and use it in GitHub Desktop.
DBInitialization class to initialize in-memory database
package org.mule.blogdemo.init;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import org.springframework.beans.factory.InitializingBean;
public class DBInitialization implements InitializingBean {
public void afterPropertiesSet() throws Exception {
String dbURL = "jdbc:derby:memory:blogdemo;create=true";
Connection conn = null;
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
// Get a connection
conn = DriverManager.getConnection(dbURL);
Statement stmt = conn.createStatement();
stmt.executeUpdate("CREATE TABLE table1 (Name VARCHAR(255), External_ID__c VARCHAR(255), Value__c INTEGER, Last_Modified TIMESTAMP)");
stmt.executeUpdate("CREATE TABLE table2 (somecolumn VARCHAR(20), somecode VARCHAR(80))");
}
catch (java.sql.SQLException sqle) {
sqle.printStackTrace();
throw sqle;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment