1 25 26 29 30 package net.killingar.forum.internal.managers; 31 32 import javax.naming.Context ; 33 import javax.naming.InitialContext ; 34 import javax.naming.NamingException ; 35 import javax.sql.DataSource ; 36 import java.sql.Connection ; 37 import java.sql.ResultSet ; 38 import java.sql.SQLException ; 39 import java.sql.Statement ; 40 41 public abstract class AbstractManager implements java.io.Serializable 42 { 43 private static final String datasource = "java:comp/env/jdbc/SKForumDS"; 44 private static Context ctx; 45 private static DataSource ds; 46 47 protected ForumManager manager; 48 49 50 53 public void initialize(ForumManager m) 54 { 55 manager = m; 56 } 57 58 61 public static Connection getNewConnection() throws SQLException 62 { 63 try 64 { 65 if (ctx == null) 66 ctx = new InitialContext (); 67 if (ds == null) 68 ds = (DataSource ) ctx.lookup(datasource); 69 return ds.getConnection(); 70 } 71 catch (NamingException e) 72 { 73 e.printStackTrace(); 74 throw new SQLException (e.getMessage()); 75 } 76 } 77 78 81 public static void closeAll(Connection c, Statement statement, ResultSet result) throws SQLException 82 { 83 if (result != null)result.close(); 84 if (statement != null)statement.close(); 85 if (c != null)c.close(); 86 } 87 public static void closeAll(Connection c, Statement statement) throws SQLException { closeAll(c, statement, null); } 88 public static void closeAll(Connection c) throws SQLException { closeAll(c, null, null); } 89 90 91 94 public void actionPerformed(String action){} 95 96 public ForumManager getManager() { return manager; } 97 } | Popular Tags |