1 25 26 29 package net.killingar.forum; 30 31 import net.killingar.Utils; 32 import net.killingar.forum.internal.managers.AbstractManager; 33 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.NamingException ; 37 import javax.sql.DataSource ; 38 import java.sql.Connection ; 39 import java.sql.SQLException ; 40 import java.sql.Statement ; 41 42 public class Install 43 { 44 public static final void main() throws Exception 45 { 46 createTables(); 47 } 48 49 public static void createTables() throws java.sql.SQLException 50 { 51 Connection c = null; 52 Statement statement = null; 53 54 try 55 { 56 try 57 { 58 Context ctx = new InitialContext (); 59 DataSource ds = (DataSource )ctx.lookup("java:comp/env/jdbc/SKForumDS"); 60 c = ds.getConnection(); 61 } 62 catch (NamingException e) 63 { 64 e.printStackTrace(); 65 throw new SQLException (e.getMessage()); 66 } 67 68 statement = c.createStatement(); 69 70 String [] statements = Utils.getResourceAsString("SKForum-install-"+(String )Utils.getProperties().get("net.killingar.forum.Install.database")+".sql").split(";"); 71 for (int i = 0; i != statements.length; i++) 72 { 73 statements[i] = statements[i].trim(); 74 try 75 { 76 statement.executeUpdate(statements[i]); 77 } 78 catch (java.sql.SQLException e) 79 { 80 System.err.println(statements[i]); 81 e.printStackTrace(); 82 } 83 } 84 } 85 catch (java.io.IOException e) 86 { 87 e.printStackTrace(); 88 throw new RuntimeException ("failed to load install sql script "+e); 89 } 90 finally { AbstractManager.closeAll(c, statement, null); } 91 } 92 } | Popular Tags |