关于PreparedStatement对象中的setBinaryStream(int paramenterIndex,InputStream x);,还有添加规则

PreparedStatement|类是预编译的Statement对象。当要执行多条语句时,且每条语句的结构相似时,可以利用此类
PreparedStatement show;
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,user,pass);
show = conn.prepareStatement(“select img_data from imgtable “+” where img_id = ?”) ;}

ResultSet rs = show.executeQuery() 在函数里面不用再输入查询的语句,直接就可以查询

其中你的问好进行传入功能
show.setInt(1,6); 前面的1为第几个问哈,6为传入的数值,还有其他的形式setXxx格式,用于?是什么类型

其中,当数据库要进行进行字节的操作时
需求:需要运用到PreparedStatement对象中的setBinaryStream(int paramenterIndex,InputStream x);该方法用于指定
参数传入二进制输入流,从而可以实现将Blob数据保存到数据库的功能
其中mediumblob对象可以存储16MB的内容 blob类型最多能存储64KB的内容

综上来连接数据库,当要查询图片的时候,利用上述代码输入id号即可查看图片
例如:show.setInt(1,1);编号为1的图片为
代码显示
try(
//执行查询
ResultSet rs = show.executeQuery()){
if(rs.next()) {
//取出blob列
Blob imgBlob = rs.getBlob(1);
//取出Blob列的数据
ImageIcon icon = new ImageIcon(imgBlob.getBytes(1L, (int)imgBlob.length()));
imageLabel.setIcon(icon);
System.out.println(“显示成功!”);
}
其中imageLabel
JLabel imageLabel = new JLabel();
panel.add(new JScrollPane(imageLabel) ,BorderLayout.CENTER);//为标签设置滚轮

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值