sun7bear
发贴: 16
积分: 0
|
于 2006-05-06 19:55
<!--测试数据源--> <%@ page contentType="text/html; charset=gb2312" %> <%@ page import="javax.naming.Context" %> <%@ page import="javax.sql.DataSource"%> <%@ page import="javax.naming.InitialContext"%> <%@ page import="java.sql.*"%>
<% DataSource ds = null; try{ Context initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup("java:comp/env"); //从Context中lookup数据源。 ds = (DataSource)envCtx.lookup("jdbc/DBPool"); if(ds!=null) { out.println("已经获得DataSource!"); out.println("<br>"); Connection conn = ds.getConnection(); Statement stmt=conn.createStatement(); ResultSet rst=stmt.executeQuery("select * from book"); out.println("以下是从数据库中读取出来的数据"); while(rst.next()) { out.println("bookName:"+rst.getString("bookName")); out.println("<br>"); } } else out.println("连接失败!"); } catch(Exception ne) { out.println(ne); } %> 我用如上jsp文件连接到mssql2000,结果显示如下错误 已经获得DataSource! org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory ([Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.) 已经获得数据源,但为什么不能取的mssql2000中的数据呢?
|