java.lang.UnsupportedOperationException: The user must supply a JDBC connection

fujingrun 2010-04-30 01:07:23



各位高手们
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
这是我在用struts2 集成Srping hibernate 的时候 当我请求数据的时候报的一个错 去搜错误原因的时候 都说是配置文件里的问题 可是我也检查了 一遍了 应该没有错误了 驱动我也加了 可是为什么还是不行呢 我就郁闷了

各位帮忙给看下好不
...全文
2350 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydq580_ 2012-10-05
  • 打赏
  • 举报
回复
只求看看我的问题,,谢谢,鼠标移到我的头像上就能看到,,谢谢,,
licip 2010-05-02
  • 打赏
  • 举报
回复
<property name="connection.url">
jdbc:mysql://localhost:3306/
</property>
后面没有指定数据库呀。
BearKin 2010-05-02
  • 打赏
  • 举报
回复
我没有办法给你更具体的信息 因为我没有在实际工作中用到过SPRING 如果不行你可以先尝试把SPRING拿掉看看是否能成功(SessionFactory我建议你先使用Myeclipse给你生成的 当然你也可以自己写 必须保证是正确的 阿门。。)
最好也测试下没有数据库名会不会出错 尽管我认为不会出错(印象里我没写数据库名的时候有很多)
BearKin 2010-05-02
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 crazylaa 的回复:]
"jdbc:mysql://localhost:3306/"丢了数据库名?
比如用test,则需要
"jdbc:mysql://localhost:3306/test"
[/Quote]

有些时候不需要数据库名的 具体啥原因俺也不知道 我用MYECLIPSE的DB BROWSER的时候从来没写过呢。。

http://www.javaeye.com/topic/86289

这个帖子说你的SessionFactory没有指定具体的配置文件路径 原文

12:15:34,250  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.Hibernate.connection.UserSuppliedConnectionProvider.getConnection (UserSuppliedConnectionProvider.java:32)
at net.sf.Hibernate.impl.BatcherImpl.openConnection(BatcherImpl.java:289)
at net.sf.Hibernate.impl.SessionImpl.connect(SessionImpl.java:3361)
at net.sf.Hibernate.impl.SessionImpl.connection(SessionImpl.java:3321)
at net.sf.Hibernate.impl.BatcherImpl.prepareQueryStatement(BatcherImpl.java:66)
at net.sf.Hibernate.loader.Loader.prepareQueryStatement(Loader.java:779)
at net.sf.Hibernate.hql.QueryTranslator.iterate(QueryTranslator.java:864)
at net.sf.Hibernate.impl.SessionImpl.iterate(SessionImpl.java:1618)
at net.sf.Hibernate.impl.QueryImpl.iterate(QueryImpl.java:27)
at com.Hibernate.person.TestQueryPerson.main(TestQueryPerson.java:28)
Exception in thread "main"
答:修改main函数,为该程序指定配置文件即可。


所以 LZ要冷静的观察自己做了什么不能做的事情 比如你在用SPRING配置了SESSION的时候 还用HIBERNATE的方式创建了个SessionFactory
tianice 2010-05-02
  • 打赏
  • 举报
回复
你配置了hibernate文件但是在spring中没有引用,spring单独配置的数据源和hibernate的参数可你没在sessionFactory中注入数据源,你可以配置直接在spring中使用原来的hibernate配置文件,也可以不用hibernate配置文件,在你的sessionFactory中注入数据源,具体的配置你可以找下spring的文档
fujingrun 2010-05-01
  • 打赏
  • 举报
回复
还是不行 我用Myeclipse 8.5 集成的S2SH 还是报那个错 不知道怎么回事 郁闷那

就是一个驱动没有连接上 各位高手在给想想吧
追求者 2010-05-01
  • 打赏
  • 举报
回复
从log开始分析原因
jumpheightway 2010-05-01
  • 打赏
  • 举报
回复
应该是你的参数有问题
要是参数没有是不会报那个错误的
风起于默 2010-04-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 crazylaa 的回复:]

"jdbc:mysql://localhost:3306/"丢了数据库名?
比如用test,则需要
"jdbc:mysql://localhost:3306/test"
[/Quote]
没数据库能出来那就奇怪了
wzju64676266 2010-04-30
  • 打赏
  • 举报
回复
up楼上两位
crazylaa 2010-04-30
  • 打赏
  • 举报
回复
"jdbc:mysql://localhost:3306/"丢了数据库名?
比如用test,则需要
"jdbc:mysql://localhost:3306/test"
  • 打赏
  • 举报
回复
你确定 jdbc:mysql://localhost:3306/ 这个 URL 是正确的?

我咋记得后还应该有个数据库的名字呢?
fujingrun 2010-04-30
  • 打赏
  • 举报
回复
这个是 hibernate.cfg.xml 的配置


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>

<session-factory>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/
</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="myeclipse.connection.profile">mysql</property>
<mapping resource="com/fjr/entity/Users.hbm.xml" />

</session-factory>

</hibernate-configuration>




这个是Spring 中的配置


<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
">


<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/"></property>
<property name="username" value="root"></property>
<property name="password" value=""></property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/fjr/entity/Users.hbm.xml</value>
</list>
</property>
</bean>

<!-- 事务管理 -->
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<aop:config>
<aop:pointcut expression="execution(* com.fjr.biz.impl.*.*(..))" id="aoppointcut"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="aoppointcut"/>
</aop:config>

<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>


<bean id="userDao" class="com.fjr.dao.impl.UserDao">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="userBiz" class="com.fjr.biz.impl.UserBiz">
<property name="userDao" ref="userDao"></property>
</bean>

<bean id="userActioin" class="com.fjr.entity.Users">
<property name="userBiz" ref="userBiz"></property>
</bean>

</beans>


Mars_Ma_OK 2010-04-30
  • 打赏
  • 举报
回复
有没有代码可以贴出来? 配置文件等.

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧