很简单,分数全部给我吧
在\server\default\deploy下,新建mysql-ds.xml文件,其内容如下<datasources>
  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name></user-name>
    <password></password>
  </local-tx-datasource>
</datasources>就以上面MySqlDS为jndi-name,下面是连接的方法Context initCtx = new InitialContext();
//这里和tomcat不一样,不需要java:comp/env
DataSource ds = initCtx.lookup(java:/MySqlDS);
if (ds != null) 
    Connection conn = ds.getConnection();

解决方案 »

  1.   

    1.Oracle与SQL Server在配置连接池时的区别:Tomcat配置文件中
    Oracle的配置方法
        <parameter>
          <name>url</name>
          <value>jdbc:oracle:thin:@172.28.122.49:1521:cpdb</value>   
        </parameter>    <parameter>
          <name>driverClassName</name>
          <value>oracle.jdbc.driver.OracleDriver</value>
        </parameter>SQL Server的配置方法
     <parameter>
      <name>url</name>
      <value>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=pubs</value>
     </parameter>   <parameter>
      <name>driverClassName</name>
      <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
     </parameter>
    注意:
    SQL Server包的取得方式
    从http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&DisplayLang=en#filelist下载"Microsoft SQL Server 2000 Driver for JDBC",并安装,得到msbase.jar,mssqlserver.jar和msutil.jar三个文件,将三个文件COPY到TOMCAT 4.1下common\lib文件夹中Oracle包的取得方式
    将\ORANT\jdbc\lib\classes12.jar COPY到TOMCAT 4.1下common\lib文件夹中2.Oracle与SQL Server在使用JDBC时的区别:
    Oracle
    String url_  = "172.28.122.49:1521:cpdb";
    String id_ = "cu01";
    String pass_ = "abc";
    Class.forName("oracle.jdbc.driver.OracleDriver");
       conn = DriverManager.getConnection("jdbc:oracle:thin:@" + url_, id_, pass_);SQL Server
    Class.forName("oracle.jdbc.driver.OracleDriver");
       conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://BLUESKY:1433;User=sa;Password=sa;DatabaseName=sitedb);
    Class.forName(driverName);
    Connection conn = DriverManager.getConnection(connURL);3.例子说明
    例子中:tomcattry.xml是Tomcat的配置文件, sample是一个连接池servlet端代码(通过comming.html启动servlet)本例子环境
    OS: Windows2000
    JDK: 1.4.2_04
    IDE: Eclipse3.0
    Web Server: Tomcat4.1.27
    Database: Oracle9i数据库表结构
    表名:
    test
    结构:
    USERNAME                                  NOT NULL VARCHAR2(10)
    PASSWORD                                           VARCHAR2(10)
    建表语句:
    create table test(username varchar(10) primary key,password varchar(10));
      

  2.   

    谢谢大家,周一回公司的时候我试验一下,如果问题解决,一定送分。再问一下。我现在的工程是用resin2.1.9和sybase11.5,单纯jsp和servlet。如果要做j2ee开发,是不是resin不支持?还是resin-ee3.0.8以上支持?需要和jboss结合吗?有关于jboss和resin配合方面的文章资料或者经验什么的吗?万分感谢!!
      

  3.   

    JBOSS本来就支持JSP、SERVLET的,JBOSS 4.0内置了tomcat 5.0,
    你做EJB的话只要一个JBOSS就够了
      

  4.   

    to angelheart:
    我知道jboss3.2.5内建了(Apache Tomcat/5.0.26),但是,我们以前的项目用的是resin2.1.9应用服务器,单纯的jsp/servlet,而且已经运行的良好,大范围内使用了。现在要做分布式计算,只能采用EJB技术,但又想尽量保持最少的变化,所以想知道jboss能不能和原先的resin配合,而不用jboss自带的tomcat。
      

  5.   

    还是不行啊。错误如下:
    HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Could not create connection; - nested throwable: (java.sql.SQLException: Cannot connect to MySQL server on mysql-hostname:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.UnknownHostException)); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Cannot connect to MySQL server on mysql-hostname:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.UnknownHostException)))
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:101)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    root cause org.jboss.util.NestedSQLException: Could not create connection; - nested throwable: (java.sql.SQLException: Cannot connect to MySQL server on mysql-hostname:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.UnknownHostException)); - nested throwable: (org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Cannot connect to MySQL server on mysql-hostname:3306. Is there a MySQL server running on the machine/port you are trying to connect to? (java.net.UnknownHostException)))
    org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:106)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:66)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: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.
    --------------------------------------------------------------------------------
      

  6.   

    我只有mysql运行在3306端口上,其他的没有占用这个端口。