ITeye博客

mysql存储过程

xiajin2080 · 2009-12-18 15:36 · 数据库 · Java · MySQL · Markdown

delimiter //
create procedure updateCity (in parameter integer)
begin

update city set postalcode='518000' where cityId=parameter;
end;
//

2.

delimiter //
create procedure selectCity ()
begin
select * from city;
end;
//

3.

 public void callProcUpdateCity(int id){
    	
    	String updateCity = "{call updateCity("+id+")}";
    	
    	String selectCity="{call selectCity()}";
    	
    	Session session=getSession();
    	Transaction tx = session.beginTransaction();
    	Connection connection=session.connection();
    	try {
			CallableStatement cstmt =connection.prepareCall(updateCity);
//			cstmt.setInt(1, id);
			cstmt.executeUpdate();
			ResultSet rs=cstmt.executeQuery(selectCity);
			while(rs.next()){
				
				System.out.println(rs.getString(2));
			}
			tx.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。