首先下载了SQl server 2005数据库连接驱动程序包sqljdbc.jar到项目目录的lib目录,
tomcat6.0conf目录下的context.xml文件你的<Context></Context>标签中加入如下配置
<Resource name="jdbc/dbpooling" auth="Container" type="javax.sql.DataSource"
password="123" user="sa"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDemo"
maxActive="100" maxIdle="30" maxWait="5000"/>然后在项目的/web-inf/目录下的web.xml配置文件中添加了如下代码:
<resource-ref>
<!--对数据库连接池的描述-->
<description>SQL Server 2005 DataSource</description>
<!--数据库连接池引用名称-->
<res-ref-name>jdbc/dbpooling</res-ref-name>
<!--数据库连接池引用类型-->
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
测试数据<%@ page language="java" import="java.sql.*,javax.sql.*,javax.naming.*" pageEncoding="gb2312"%>
<html>
<head><title>全部注册用户信息</title></head>
<body>
<%
try{
DataSource ds=null;
InitialContext ctx=new InitialContext(); //建立上下文
//通过JNDI查找数据连接池
ds=(DataSource) ctx.lookup("java:comp/env/jdbc/dbpooling");
Connection conn=ds.getConnection(); //获取数据库连接对象
//创建PreparedState对象
PreparedStatement pstate=conn.prepareStatement("select * from [User]");
ResultSet rs=pstate.executeQuery();
out.println("<table border=1>");
out.println("<tr><td>用户名</td><td>密码</td></tr>");
//遍历显示结果集中的数据
while(rs.next()){
out.println("<tr><td>");
out.println(rs.getString(2));
out.println("</td><td>");
out.println(rs.getString(3));
out.println("</td></tr>");
}
out.println("</table>");
}catch(SQLException e){
out.println(e);
}
%></body></html>库连接池的jsp页面的代码为:
tomcat6.0conf目录下的context.xml文件你的<Context></Context>标签中加入如下配置
<Resource name="jdbc/dbpooling" auth="Container" type="javax.sql.DataSource"
password="123" user="sa"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=TestDemo"
maxActive="100" maxIdle="30" maxWait="5000"/>然后在项目的/web-inf/目录下的web.xml配置文件中添加了如下代码:
<resource-ref>
<!--对数据库连接池的描述-->
<description>SQL Server 2005 DataSource</description>
<!--数据库连接池引用名称-->
<res-ref-name>jdbc/dbpooling</res-ref-name>
<!--数据库连接池引用类型-->
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
测试数据<%@ page language="java" import="java.sql.*,javax.sql.*,javax.naming.*" pageEncoding="gb2312"%>
<html>
<head><title>全部注册用户信息</title></head>
<body>
<%
try{
DataSource ds=null;
InitialContext ctx=new InitialContext(); //建立上下文
//通过JNDI查找数据连接池
ds=(DataSource) ctx.lookup("java:comp/env/jdbc/dbpooling");
Connection conn=ds.getConnection(); //获取数据库连接对象
//创建PreparedState对象
PreparedStatement pstate=conn.prepareStatement("select * from [User]");
ResultSet rs=pstate.executeQuery();
out.println("<table border=1>");
out.println("<tr><td>用户名</td><td>密码</td></tr>");
//遍历显示结果集中的数据
while(rs.next()){
out.println("<tr><td>");
out.println(rs.getString(2));
out.println("</td><td>");
out.println(rs.getString(3));
out.println("</td></tr>");
}
out.println("</table>");
}catch(SQLException e){
out.println(e);
}
%></body></html>库连接池的jsp页面的代码为:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (用户 '' 登录失败。该用户与可信 SQL Server 连接无关联。) 哪里出问题了啊 求高手解答啊 ...
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://127.0.0.1:1433;databaseName=dahua">
</property>
<property name="username" value="sa"></property>
<property name="password" value="111111"></property>
</bean>
spring配置文件中导入