怎样直连jdbc?hibernate+spring

life923 2010-05-12 01:49:23
提示
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
org.hibernate.connection.UserSuppliedConnectionProvider.closeConnection(UserSuppliedConnectionProvider.java:37)
com.action.TestAction.execute(TestAction.java:55)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)



public String execute() throws Exception {
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String sql="select * from xt";
try {
conn = cp.getConnection();
st = conn.createStatement();
rs = st.executeQuery(sql);
if(rs.next()){
System.out.println((String)rs.getString("name"));
}
} catch (SQLException e) {
e.printStackTrace();
}
finally{
try {
cp.closeConnection(conn);
} catch (SQLException e) {
e.printStackTrace();
}
}
return SUCCESS;
}
...全文
340 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
life923 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ditouye 的回复:]
LZ,既然想用JDBC,为何还用hibernate?
JDBC的连接:
Class.forName(driver);
DriverManager.getConnection(url,user, password);
这样不就可以了吗?
[/Quote]

我只是在系统的某些地方用JDBC直接,系统其他大部分 都还是hibernate

而且我不想重新定义数据库用户,密码,
应该可以直接获取hibernate的连接吧
hepeng_8 2010-05-12
  • 打赏
  • 举报
回复
hibernate中连接数据源,封装了数据库连接等操作,
ditouye 2010-05-12
  • 打赏
  • 举报
回复
LZ,既然想用JDBC,为何还用hibernate?
JDBC的连接:
Class.forName(driver);
DriverManager.getConnection(url,user, password);
这样不就可以了吗?
life923 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 hepeng154833488 的回复:]
还不知道你要说的问题是什么?
[/Quote]

Connection conn = null;
Statement st = null;
ResultSet rs = null;
String sql="select * from test";
conn = //这边怎么从hibernate+spring中获取连接????????
st = conn.createStatement();
rs = st.executeQuery(sql);
hepeng_8 2010-05-12
  • 打赏
  • 举报
回复
还不知道你要说的问题是什么?
life923 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 vsvsvsvsvsvsvsvsvsvs 的回复:]
hibernate中连接数据源,封装了数据库连接等操作,
[/Quote]
我想直接连的话 怎么操作呢?
life923 2010-05-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yanghuistart 的回复:]
还不知道你要说的问题是什么?
[/Quote]
就是如何在hibernate+spring的系统中获得 jdbc的Connection ?
  • 打赏
  • 举报
回复
hibernate中连接数据源,封装了数据库连接等操作,
  • 打赏
  • 举报
回复
hibernate中连接数据源,封装了数据库连接等操作,
oceantang 2010-05-12
  • 打赏
  • 举报
回复
帮顶。。。
yanghuistart 2010-05-12
  • 打赏
  • 举报
回复
还不知道你要说的问题是什么?
米尤人 2010-05-12
  • 打赏
  • 举报
回复
问题不太具体

81,092

社区成员

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

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