刚下了最新的jboss-4.0.2 和 mysql-4.1 配置访问数据库不成功,高手快来看看 还得要将mysql 的jdbc驱动放进去 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 回 sunyanbing(流星) :不好意思,我没说清楚,mysql 的 jdbc驱动程序也已经放到 default/lib 目录下了. 如果没有jdbc驱动程序,jboss 分析 mysql-ds.xml 是会报未找到 com.mysql.jdbc.Driver 类的错误. 结贴了,问题解决. 在代码里引用JNDI的名字写错了. java:comp/env/jdbc/mysqlds 这么写应该是正确的,但在我的JBOSS配置里应该这么写; java:/mysqlds 另外 mysqlds 也写错了 ^_^ 应该是 mysqldb\结贴!! 后记:java:comp/env/jdbc/mysqlds 这样的写法是JBOSS resource environment reference 的配置.在WEB-INF下的web.xml, jboss-web.xml 里配置相应的 resource-ref 就能通过那样的方式访问数据源. 最终配置如下:<!-- web.xml --><web-app> <resource-ref> <res-ref-name>jdbc/mysqlds</res-ref-name> <res-type>javax.sql.DataSource</res-type> <jndi-name>java:/mysqlds</jndi-name> <res-auth>Container</res-auth> </resource-ref></web-app> <!-- jboss-web.xml --><jboss-web> <resource-ref> <description>mySql datasource</description> <res-ref-name>jdbc/mysqlds</res-ref-name> <res-type>javax.sql.DataSource</res-type> <jndi-name>java:/mysqlds</jndi-name> <res-auth>Container</res-auth> </resource-ref></jboss-web><!-- mysql-ds.xml --><datasources> <local-tx-datasource> <jndi-name>mysqlds</jndi-name> <connection-url>jdbc:mysql://localhost:3306/jbosstest</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>root</user-name> <password>root</password> <min-pool-size>5</min-pool-size> <max-pool-size>20</max-pool-size> <idle-timeout-minutes>5</idle-timeout-minutes> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource></datasources> 为什么使用myeclipse8.5和9.0开发EXTJS时候就爆卡,6.5却没事? 怎么用struts2标签获得文件的全路径? 请大家给推荐一个面向对象的数据库设计工具 小妹请问struts和xml的关系如何? 哪个高手能帮忙做一下,送高分,在线等呀,救命呀 请教一个关于jndi的问题 如何整合JB7和JBoss3.x jbuilder中的enterprise server5.1解破 在XML中取NODE属性的问题 Struts2 ModelDriven 问题 请问谁有oscache的非页面缓存的例子?? 怎样将Tomcat打进服务里面?
不好意思,我没说清楚,mysql 的 jdbc驱动程序也已经放到 default/lib 目录下了. 如果没有jdbc驱动程序,jboss 分析 mysql-ds.xml 是会报未找到 com.mysql.jdbc.Driver 类的错误.
\
结贴!!
java:comp/env/jdbc/mysqlds 这样的写法是JBOSS resource environment reference 的配置.在WEB-INF下的web.xml, jboss-web.xml 里配置相应的 resource-ref 就能通过那样的方式访问数据源. 最终配置如下:<!-- web.xml -->
<web-app>
<resource-ref>
<res-ref-name>jdbc/mysqlds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/mysqlds</jndi-name>
<res-auth>Container</res-auth>
</resource-ref>
</web-app> <!-- jboss-web.xml -->
<jboss-web>
<resource-ref>
<description>mySql datasource</description>
<res-ref-name>jdbc/mysqlds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:/mysqlds</jndi-name>
<res-auth>Container</res-auth>
</resource-ref>
</jboss-web>
<!-- mysql-ds.xml --><datasources>
<local-tx-datasource>
<jndi-name>mysqlds</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/jbosstest</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>root</password>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>5</idle-timeout-minutes>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>