banq兄帮忙,已经被折磨一个星期了eclipse2.1.3,jboss3.2.5中配置mysql4

04-09-17 摩卡碳烧

我想在jboss3.2.5中配置mysql数据库,怎么配置JNDI?看了几篇文章,和我

用的jboss版本不一致,配置文件也不一样

d:\jboss3.2.5(Apache Tomcat/5.0.26)
d:\eclispe2.1.3
d:\mysql4.0.16
mysql 用户名root 密码root
数据库tsb tsb数据库用户名tsb,密码tsb
mysql的mysql-2.0.14.jar也已经放到D:\jboss-3.2.5\server\default\lib

========================================
D:\jboss-3.2.5\server\default\deploy\mysql-ds.xml

<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    

<connection-url>jdbc:mysql://localhost:3306/tsb?useUnicode=true&am

p;characterEncoding=GBK&autoReconnect=true</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>root</password>
  </local-tx-datasource>
</datasources>


=======================================

D:\jboss-3.2.5\server\default\conf\standardjaws.xml

<jaws>
   <datasource>java:/MySqlDS</datasource>
   <type-mapping>mySql</type-mapping>
   <debug>false</debug>
   ................

===============================================
D:\jboss-3.2.5\server\default\conf\standardjbosscmp-jdbc.xml

<jbosscmp-jdbc>

   <defaults>
      <datasource>java:/MySqlDS</datasource>
      <datasource-mapping>mySql</datasource-mapping>
       ................................


================================================

D:\jboss-3.2.5\server\default\conf\login-config.xml

<policy>
       <application-policy name = "MySqlDbRealm"> 
        <authentication>   
         <login-module code = 

"org.jboss.resource.security.ConfiguredIdentityLoginModule" 
           flag = "required"> 
            <module-option name ="principal">sa</module-option> 
            <module-option name ="userName">root</module-option> 
           <module-option name ="password">root</module-option> 
            <module-option name ="managedConnectionFactoryName"> 
               jboss.jca:service=LocalTxCM,name=MySqlDS 
            </module-option> 
         </login-module> 
        </authentication> 
       </application-policy> 
       ........................................
</policy>     
=================================
MyWeb/index.jsp


<!-- Copyright (c) 2002 by ObjectLearn. All Rights Reserved. -->
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import='java.sql.*' %>
<%@ page import='javax.sql.*' %>
<%@ page import='javax.naming.*' %>
<html>
	<head>
		<title>Welcome</title>
	</head>
	<body>
<%

Context env = (Context) new 

InitialContext().lookup("java:comp/env");
DataSource source = (DataSource) env.lookup("MySqlDS");

Connection conn = source.getConnection();	     
Statement stmt = conn.createStatement();
ResultSet rs = null;
rs = stmt.executeQuery("select tpid,tpname from type");
%>	
<table>
 <%while(rs.next()){%>
 <tr>
    <td><%=rs.getInt(1)+" "+rs.getString(2)%></td>
 </tr>
 <%
 }
 %>
</table>	
<%
rs.close();
stmt.close();
conn.close();
%>
	</body>
</html>

<p class="indent">


错误信息:
在eclipse中启动jboss,在ie中运行

http://localhost:8080/MyWeb/index.jsp


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that

prevented it from fulfilling this request.

exception

javax.servlet.ServletException: MySqlDS not bound


org.apache.jasper.runtime.PageContextImpl.doHandlePageException(Pa

geContextImpl.java:825)


org.apache.jasper.runtime.PageContextImpl.handlePageException(Page

ContextImpl.java:758)
org.apache.jsp.index_jsp._jspService(index_jsp.java:98)


org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)


javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrap

per.java:324)


org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.jav

a:292)


org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)


javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

javax.naming.NameNotFoundException: MySqlDS not bound


org.jnp.server.NamingServer.getBinding(NamingServer.java:495)


org.jnp.server.NamingServer.getBinding(NamingServer.java:503)


org.jnp.server.NamingServer.getObject(NamingServer.java:509)
org.jnp.server.NamingServer.lookup(NamingServer.java:282)
org.jnp.server.NamingServer.lookup(NamingServer.java:256)


org.jnp.interfaces.NamingContext.lookup(NamingContext.java:530)


org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
org.apache.jsp.index_jsp._jspService(index_jsp.java:61)


org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)


javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrap

per.java:324)


org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.jav

a:292)


org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)


javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


note The full stack trace of the root cause is available in the

Apache Tomcat/5.0.26 logs.

现在想做j2ee开发,主要是现在项目中需要分布式计算,我已经被折磨1个多星期了,各位朋友帮帮忙

yanbuhan
2004-09-17 18:35

我觉得你在web.xml中是不是需要指定对MySqlDS的资源引用呢?否则就可能会出现你的问题。

摩卡碳烧
2004-09-19 18:37

没看到说需要修改web.xml的文章阿

Azure_2003
2004-09-20 11:00

自己去设计一个分布式计算方案吧,就不会这么痛苦了。

banq
2004-09-24 09:40

将JBoss/DOCS/JCA下的mysql-ds.xml拷贝到server/default/deploy下,改写mysql-ds.xml,记住其中的JNDI名称,在程序中以java:/JNDI名称调用即可。

SportsBaby1980
2004-09-24 13:21

这是个基本问题。

应该多找些资料看一下。