如何在TOMCAT 4.0中配制SQLServer 2000数据库数据源(100分)

  • 主题发起人 主题发起人 hooyu
  • 开始时间 开始时间
H

hooyu

Unregistered / Unconfirmed
GUEST, unregistred user!
在server.xml的的设置:
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="com.microsoft.jdbcx.sqlserver.SQLServerDriver"
connectionURL="jdbc:microsoft:sqlserver://server1:1433;User=sa;Password="
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
 
启动服务后出错如下:
Create Catalina server
Starting service Tomcat-Standalone
Apache Tomcat/4.0
Catalina.start: LifecycleException: Exception opening database connection: java.sql.SQLException: com.microsoft.jdbcx.sqlserver.SQLServerDriver
LifecycleException: Exception opening database connection: java.sql.SQLException: com.microsoft.jdbcx.sqlserver.SQLServerDriver
at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:615)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:307)
at org.apache.catalina.core.StandardService.start(StandardService.java:388)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:505)
at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:360)
----- Root Cause -----
java.sql.SQLException: com.microsoft.jdbcx.sqlserver.SQLServerDriver
at org.apache.catalina.realm.JDBCRealm.open(JDBCRealm.java:538)
at org.apache.catalina.realm.JDBCRealm.start(JDBCRealm.java:613)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1108)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:307)
at org.apache.catalina.core.StandardService.start(StandardService.java:388)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:505)
at org.apache.catalina.startup.CatalinaService.start(CatalinaService.java:261)
at org.apache.catalina.startup.CatalinaService.execute(CatalinaService.java:172)
at org.apache.catalina.startup.Catalina.process(Catalina.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.BootstrapService.main(BootstrapService.java:360)
 
这部分作用高手是否可以帮我说明一下?
<Resource name="jdbc/HomeMakingDataBase" auth="SERVLET"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/TestDB">
<parameter><name>user</name><value>sa</value></parameter>
<parameter><name>password</name><value></value></parameter>
<parameter><name>driverClassName</name>
<value>org.hsql.jdbcDriver</value></parameter>
<parameter><name>driverName</name>
<value>jdbc:HypersonicSQL:database</value></parameter>
</ResourceParams>
 
你多写了个'x',应该是:[red]com.microsoft.jdbc.sqlserver.SQLServerDriver[/red]
<Realm className="org.apache.catalina.realm.JDBCRealm" debug="99"
driverName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
connectionURL="jdbc:microsoft:sqlserver://server1:1433;User=sa;Password="
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />
 
学习,借分
 
<%@ page contentType="text/html;
charset=GBK" %>;
<%@ page import="java.sql.*" %>;
<%@ page import="javax.naming.Context" %>;
<%@ page import="javax.naming.InitialContext" %>;
<%@ page import="javax.sql.DataSource" %>;

<html>
<head>
<title>
测试数据源连接(或Pool数据池化)
</title>
</head>
<body bgcolor="#ffffff">
<h1>
测试数据源连接(或Pool数据池化)
</h1>
<Table>
<%
Connection conn = null;
try {
Context ctx = (Context) new InitialContext().
lookup("java:comp/env");
conn = ((DataSource) ctx.lookup("jdbc/homemaking")).
getConnection();
}
catch (Exception e) {
System.out.println("ABC");}
try {
Statement ps = conn.createStatement();

ResultSet rs = ps.executeQuery("select * from sysobjects");
while (rs.next()) {
System.out.println("<TR><TD>"+rs.getString(1)+"</TD></TR>");
}
}
catch (Exception e) {
System.out.println("ABC");}

%>
</Table>
</body>
</html>
 

<Context path="/homemaking"do
cBase="e:/hongyuan/webapps/homemaking/" debug="0" reloadable="true">
<Resource name="jdbc/HomeMakingDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/HomeMakingDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:microsoft:sqlserver://192.168.1.64:1433;DatabaseName=HomeMaking</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>sa</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
</ResourceParams>
</Context>
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<resource-ref>
<description>
Resource reference to java.sql.Connection
factory defined in server.xml
</description>
<res-ref-name>jdbc/homemakingdb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
 
以上是分别是我的JSP/SERVER.XML/WEB.XML,我运行JSP时无法显示数据,即连接数据源出错,请问是何问题?
 
你的SQl Server 的JDBC驱动包有没有拷贝到tomcat的lib目录下
 
我已经在CALSSPATH设置了啊:
E:/HongYuan/Install/j2sdk1.4.1_01/lib;E:/HongYuan/Install/Tomcat 4.1/common/lib/*.jar;E:/HongYuan/Install/Tomcat 4.1/server/lib/*.jar;E:/HongYuan/Install/JDBC_Driver/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar;E:/HongYuan/Install/JDBC_Driver/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar;E:/HongYuan/Install/JDBC_Driver/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar;E:/HongYuan/Install/Tomcat 4.1/common/lib/naming-factory.jar;E:/HongYuan/Install/Tomcat 4.1/common/lib/naming-common.jar;E:/HongYuan/Install/Tomcat 4.1/common/lib/naming-resources.jar;
 
唉,又是没有结果啊?算了...........
 
javax.naming.NameNotFoundException: Name java: is not bound in this Context
 
to hooyu;
在CLASSPATH里面设置了好像对TOMCAT没用!我建议你还是拷贝到tomcat的lib目录下
 
文件已经复制,但还是出错,今天看到人工代码注册JNDI的代码,不太明白,可否帮我看看?
//Hashtable env = new Hashtable();
//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
//env.put(Context.PROVIDER_URL, "file:d:/org");
//Trying to create the naming service initial context
//Context ctx = new InitialContext(env);

//SQLServer DataSources
//SQLServerDataSource mds = new SQLServerDataSource();
//mds.setDescription("My SQLServerDataSource");
//mds.setServerName("192.168.1.64");
//mds.setPortNumber(1433);
//mds.setDatabaseName("HomeMaking");
//mds.setSelectMethod("cursor");

其中:com.sun.jndi.fscontext.RefFSContextFactory类未找到,不知在那个包中
 
1,修改你的Server.xml文件:
<Context path="/mt"do
cBase="C:/mt/SourceCode/web" debug="0"
reloadable="true" crossContext="true">
<Resource name="jdbc/mtDbSource" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/mtDbSource">
<parameter>
<name>url</name>
<value>jdbc:sybase:Tds:192.168.0.3:7777/mt</value>
</parameter>
<parameter>
<name>password</name>
<value>mt2003</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.sybase.jdbc2.jdbc.SybDriver</value>
</parameter>
<parameter>
<name>username</name>
<value>mt</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>5</value>
</parameter>
</ResourceParams>

</Context>
2,修改你的WEB-INF文件;
在<web-app>中加入:
<resource-ref>
<description>MT Database Source</description>
<res-ref-name>jdbc/mtDbSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
 
多人接受答案了。
 
后退
顶部