81,094
社区成员
发帖
与我相关
我的任务
分享
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;
}