Created
September 22, 2012 19:28
-
-
Save adrianhsieh/3767518 to your computer and use it in GitHub Desktop.
DBInitialization class to initialize in-memory database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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