使用CallableStatement存储过程查询数据库

来源:互联网 发布:淘宝小棉袄衣服 编辑:程序博客网 时间:2024/04/28 00:56
使用CallableStatement存储过程查询数据库

package jdbctest01;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;

import com.lile.jdbc.util.DBUtil;

public class Demo2 {
    public static void main(String[] args) {
        //连接数据库
        Connection conn = DBUtil.getConnection();
        PreparedStatement pst = null;
        
        try {
            CallableStatement cs=conn.prepareCall("{call sp06(?,?)}");
            cs.setInt(1, 1);
            cs.registerOutParameter(2, Types.VARCHAR);
            cs.execute();
            String bookName = cs.getString("t_bookName");
            DBUtil.closeConn(conn, pst);
            System.out.println("bookName:"+bookName);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
0 0
原创粉丝点击