1、调用存储过程 try{ Session session = daoA.getMySession(); session.flush(); Connection con = session.connection(); String procedure = "{call Update_Agent_Product_Price(?)}"; CallableStatement cstmt = con.prepareCall(procedure); cstmt.setLong(1, productId); cstmt.executeUpdate(); } catch(Exception e){ e.printStackTrace(); } 2、查询 try{ Session session = daoA.getMySession(); session.flush(); Connection con = session.connection(); List list = new ArrayList(); StringBuffer sql = new StringBuffer(); sql.append("select * from Albuminfo albuminfo where 1=1"); if(userId != -1) { sql.append(" and albuminfo.userid = ").append(userId); } sql.append(" order by albuminfo.created desc"); Statement stmt = (Statement) con.createStatement(); ResultSet rs = stmt.executeQuery(sql.toString()); while(rs.next()) { System.out.println(rs.getString(1));//打印表的第一列 } } catch(Exception e){ e.printStackTrace(); }