本篇文章主要介绍了" 使用CallableStatement存储过程查询数据库",主要涉及到方面的内容,对于MySql感兴趣的同学可以参考一下:
使用CallableStatement存储过程查询数据库package jdbctest01;import java.sql.CallableStatement...
使用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(); } }}
以上就介绍了 使用CallableStatement存储过程查询数据库,包括了方面的内容,希望对MySql有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_3558493.html