import java.sql.*; import org.hibernate.Session;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import oracle.jdbc.driver.OracleTypes;public class TestService extends HibernateDaoSupport { public void find(){ String sql = "{call proc_st(?,?,?,?)}"; ResultSet rs = null; Session session = this.getSession(); Connection con = session.connection(); CallableStatement ctmt = null; try { ctmt = con.prepareCall(sql); ctmt.setInt(1,2); ctmt.setInt(2,5); ctmt.setString(3, "stu"); ctmt.registerOutParameter(4, OracleTypes.CURSOR); ctmt.execute(); System.out.println("name:"+ctmt.getString(2)); rs = (ResultSet)ctmt.getObject(4); while(rs.next()){ System.out.println(" stuname: "+rs.getString(2)); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ try { ctmt.close(); con.close(); session.close(); } catch (Exception e) { // TODO: handle exception } }// return list; } public static void main(String[] args) { System.out.println("test"); ApplicationContext ctx = new FileSystemXmlApplicationContext(new String("WebRoot/WEB-INF/applicationContext.xml")); TestService ts = (TestService)ctx.getBean("TestService"); ts.find(); System.out.println("ok"); }}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货