jndi连接池配置
以tomcat6.0为例:
讲数据库驱动jar包导入到tomcat6.0的/lib下,修改以下类
//连接数据库的类
class connectDB:
public static Connection getConnection(){
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/restrant");
conn = ds.getConnection();
}
在你的项目的配置文件web.xml中增加下面一段:
web.xml
最后,在tomcat/webapps/yourpro/META-INF/下增加context.xml文件
新建txt文件,复制下面代码,重命名为context.xml
//增加数据库驱动,我的是sqlserver2005
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
//指定数据库,并定义登录名和密码
url="jdbc:sqlserver://localhost:1433;databaseName=restrant"
username="sa" password="sa" maxActive="200" maxIdle="10"
maxWait="-1"/>
重新启动服务器