在ejb3中,跨域连个不同的mysql数据库 ,插入数据时为什么会有异常呢:怎么解决呢? 10
我的相关配置:<persistence-unitname="Jpa03DatebasePU"transaction-type="JTA"><jta-data-source...
我的相关配置:
<persistence-unit name="Jpa03DatebasePU" transaction-type="JTA">
<jta-data-source>java:/mysql</jta-data-source>
<class>com.renshuang.po.Person</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect
"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="jpa03PU" transaction-type="JTA">
<jta-data-source>java:/mysql1</jta-data-source>
<class>com.renshuang.po.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect
"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit> 展开
<persistence-unit name="Jpa03DatebasePU" transaction-type="JTA">
<jta-data-source>java:/mysql</jta-data-source>
<class>com.renshuang.po.Person</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect
"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="jpa03PU" transaction-type="JTA">
<jta-data-source>java:/mysql1</jta-data-source>
<class>com.renshuang.po.User</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect
"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
</properties>
</persistence-unit> 展开
2个回答
展开全部
<xa-datasource jndi-name="java:/MysqlDS1" pool-name="MysqlDS1" use-java-context="false">
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/test1?characterEncoding=UTF-8
</xa-datasource-property>
<xa-datasource-property name="User">
root
</xa-datasource-property>
<xa-datasource-property name="Password">
abc
</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver>mysql</driver>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<no-tx-separate-pools>true</no-tx-separate-pools>
</xa-pool>
</xa-datasource>
<xa-datasource jndi-name="java:/MysqlDS2" pool-name="MysqlDS2" use-java-context="false">
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/test2?characterEncoding=UTF-8
</xa-datasource-property>
<xa-datasource-property name="User">
root
</xa-datasource-property>
<xa-datasource-property name="Password">
abc
</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver>mysql</driver>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<no-tx-separate-pools>true</no-tx-separate-pools>
</xa-pool>
</xa-datasource>
<drivers>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/test1?characterEncoding=UTF-8
</xa-datasource-property>
<xa-datasource-property name="User">
root
</xa-datasource-property>
<xa-datasource-property name="Password">
abc
</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver>mysql</driver>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<no-tx-separate-pools>true</no-tx-separate-pools>
</xa-pool>
</xa-datasource>
<xa-datasource jndi-name="java:/MysqlDS2" pool-name="MysqlDS2" use-java-context="false">
<xa-datasource-property name="URL">
jdbc:mysql://localhost:3306/test2?characterEncoding=UTF-8
</xa-datasource-property>
<xa-datasource-property name="User">
root
</xa-datasource-property>
<xa-datasource-property name="Password">
abc
</xa-datasource-property>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
<driver>mysql</driver>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<no-tx-separate-pools>true</no-tx-separate-pools>
</xa-pool>
</xa-datasource>
<drivers>
<driver name="mysql" module="com.mysql.jdbc">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
展开全部
把你的异常贴出来。。。。。。。。
更多追问追答
追问
Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
追答
根据这个错误提示是没有连接上数据库
首先看你的数据库端口是否打开,在运行窗口中输入cmd 然后 输入telnet localhost 3306 看是否可以连接上,如果可以那么就看你的连接数据库的代码是否正确,仔细检查,有时候就是因为一个单词写错造成的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询