调用存储过程

public void queryProce( final int deptNo,final  String dname,final  String loc) {
System.out.println(" 进入");
//没有参数的存储过程
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
   SQLQuery sqlQuery = session.createSQLQuery("{call myproc(?,?,?)}");
            sqlQuery.setInteger(0, deptNo);
            sqlQuery.setString(1, dname);
            sqlQuery.setString(2, loc);
            sqlQuery.executeUpdate();
//SQLQuery sqlQuery = session.createSQLQuery("{call myproc3}");
  //sqlQuery.executeUpdate();
return null;
}

});

}

public Map<String, Object> queryProceList( final int deptNo, String dname, String loc) {
// TODO Auto-generated method stub
//System.out.println("进入"+deptNo);
final Map<String, Object> map=new HashMap();
this.getHibernateTemplate().execute(new HibernateCallback(){

public Object doInHibernate(Session session) throws HibernateException, SQLException {
Connection conn = session.connection();
CallableStatement procout = conn.prepareCall ("{call myproc4(?,?,?)}");  
   procout.setInt(1, deptNo);
       procout.registerOutParameter (2, Types.VARCHAR);  
       procout.registerOutParameter (3, Types.VARCHAR);  
       procout.execute ();  
       System.out.println ("\nOut argument to procout in PL/SQL block is:\n\t" +  
                            procout.getString(2) + " " + procout.getString (3));
      map.put("vale1", procout.getString(2));
   map.put("vale2", procout.getString (3));
       procout.close();  
return null;
}
});
return map;
}









//Call a procedure with an IN parameter  
    {  
      CallableStatement procin = conn.prepareCall ("begin procin (?, ?); end;");  
      procin.setInt (1, 303);  
      procin.setString (2, "Australia");  
      procin.execute ();  
      System.out.println("\ndump table regions after calling to procin--" 
                         + "insert 303 Australia\n");  
      dumpTable (conn);  
      procin.close();  
    }  
 
    // Call a procedure with an OUT parameter  
    {  
      CallableStatement procout = conn.prepareCall ("begin procout (?, ?); end;");  
      procout.registerOutParameter (1, Types.INTEGER);  
      procout.registerOutParameter (2, Types.CHAR);  
      procout.execute ();  
      System.out.println ("\nOut argument to procout in PL/SQL block is:\n\t" +  
                           procout.getInt (1) + " " + procout.getString (2));  
      procout.close();  
    }  
 
    // Call a procedure with an IN/OUT prameter  
    // This will insert "404, North Pole" instead of "303, Mars" that  
    // are in PL/SQL block of procedure procinout into table regions  
    {  
      CallableStatement procinout = conn.prepareCall ("begin procinout (?, ?); end;");  
      procinout.registerOutParameter (1, Types.INTEGER);  
     procinout.registerOutParameter (2, Types.VARCHAR);  
      procinout.setInt (1, 404);  
      procinout.setString (2, "North Pole");  
      procinout.execute ();  
      System.out.println ("\ndump table regions after calling to procinout--" 
                          + "insert 404 North Pole\n");  
      dumpTable (conn);  
      System.out.println ("Out argument in PL/SQL block definition of procinout is:\n\t" +  
                          procinout.getInt (1) + " " + procinout.getString (2));  
      procinout.close();  
    }  
 
    // Call a function with no parameters  
    {  
      CallableStatement funcnone = conn.prepareCall ("begin ? := funcnone; end;");  
      funcnone.registerOutParameter (1, Types.CHAR);  
      funcnone.execute ();  
      System.out.println ("\nReturn value of funcnone is: " + funcnone.getString (1));  
      funcnone.close();  
    }  
 
    // Call a function with an IN parameter  
    {  
      CallableStatement funcin = conn.prepareCall ("begin ? := funcin (?); end;");  
      funcin.registerOutParameter (1, Types.CHAR);  
      funcin.setString (2, "testing");  
      funcin.execute ();  
      System.out.println ("\nReturn value of funcin is: " + funcin.getString (1));  
      funcin.close();  
    }  
 
    // Call a function with an OUT parameter  
    {  
      CallableStatement funcout = conn.prepareCall ("begin ? := funcout (?); end;");  
      funcout.registerOutParameter (1, Types.CHAR);  
      funcout.registerOutParameter (2, Types.CHAR);  
      funcout.execute ();  
      System.out.println ("\nReturn value of funcout is: " + funcout.getString (1));  
      System.out.println ("Out argument is: " + funcout.getString (2));  
      funcout.close();  
    } 

你可能感兴趣的:(存储过程)