标签:hibernate jdbc hibernate执行jdbc语法
/** * 调用存储过程 * * @param PRONAME * @return */ public CallableStatement citePro(final String PRONAME){ Session session = getCurrentSession(); CallableStatement pro = session.doReturningWork(new ReturningWork<CallableStatement>() { @Override public CallableStatement execute(Connection connection) throws SQLException { CallableStatement resultSet = connection.prepareCall(PRONAME); return resultSet; } }); return pro; }
或者
/** * 使用JDBC执行sql语句 * * @return */ public void xx() throws SQLException { Session session = getCurrentSession(); ResultSet resultSet=session.doReturningWork( new ReturningWork<ResultSet>() { @Override public ResultSet execute(Connection connection) throws SQLException { String sql="select * from tableName"; PreparedStatement preparedStatement=connection.prepareStatement(sql); ResultSet resultSet=preparedStatement.executeQuery(); return resultSet; } } ); while (resultSet.next()){ System.out.println("rs:"+resultSet.getString("authid")); } }就是这个doReturnWork方法,里面通过内部类,把resultset对象一层一层返回给这个doReturnWork,这样就可以像用jdbc一样使用hibernate了。
标签:hibernate jdbc hibernate执行jdbc语法
原文地址:http://blog.csdn.net/u013474104/article/details/44513243