三、如何在jsp中使用
try{
File log = new File(\"d:\\\\pool.log\");
PrintWriter logPrint = new PrintWriter(log);
Context initContext = new InitialContext();
if (initContext == null)
logPrint.append(\"无配置环境\");
Context envContext = (Context)initContext.lookup(\"java:/comp/env\");
DataSource ds = (DataSource)envContext.lookup(\"jdbc/guestbook\");
if (ds == null)
logPrint.append(\"没有匹配数据库\");
logPrint.close();
conn = ds.getConnection();
//do your work
}catch(Exception e){
e.printStackTrace();[Page]
}finally{
conn.close(); //不会释放资源,只是将资源还给连接池
}