<Context docBase="" path="" reloadable="true" source="com.ibm.wtp.web.server:tomcat">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="tomcat_log." suffix=".txt"
timestamp="true"/>
<Resource name="jdbc/SqlServer"
auth="Container"
type="javax.sql.DataSource"
reloadable="true"/>
<ResourceParams name="jdbc/SqlServer">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>123</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://127.0.0.1:1433/BakBlog</value>
</parameter>
</ResourceParams>
</Context>
以上是配置数据连接的Context
程序中:
<%@ page contentType = "text/html;charset=gb2312" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "javax.sql.*" %>
<%@ page import = "javax.naming.*" %>
< html >
< body >
<%
DataSource ds = null ;
Connection conn = null ;
ResultSet rs = null ;
java.sql.Statement stmt = null ;
InitialContext ctx = null ;
try
{
ctx =new InitialContext ();
ds =( DataSource ) ctx . lookup ( "jdbc/SqlServer" );
conn = ds . getConnection ();
stmt = conn . createStatement ();
String strSql = " select * from admin" ; 表
rs = stmt . executeQuery ( strSql );
while( rs . next ())
{
out . println ( rs . getString ( 1 ) + "" );
out . println ( rs . getString ( 2 ) + "" );
}