日期:2014-05-17 浏览次数:20911 次
public class DBPool { private static DataSource pool; static { Context env = null; try { env = (Context) new InitialContext().lookup("java:comp/env"); pool = (DataSource) env.lookup("jdbc/DBpool"); if(pool == null) System.err.println("'DBpool' is an unknown DataSource"); } catch (NamingException ne) { ne.printStackTrace(); } } public static DataSource getPool() { return pool; } }
public byte[] getStaticEntiy(String pmname, int scalesize, float x, float y) { byte[] bContent = null; try { conn = DBPool.getPool().getConnection(); //获取连接池中的链接 bContent = scaledao.getStaticEntiy(pmname, scalesize, x, y, conn); //这是一般的从数据库读取流数据的方法 } catch (SQLException e) { e.printStackTrace(); } finally { if(conn!=null){ try { conn.close(); //释放链接 } catch (SQLException e) { e.printStackTrace(); } } } return bContent; }