在不保存文件的情况下读取Blob文件 [英] Read Blob file without saving it a file

查看:51
本文介绍了在不保存文件的情况下读取Blob文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划使用作为Blob存储在数据库中的公共密钥对字符串进行加密.我创建了名为 readBlob()的方法来读取密钥并将其保存到文件中./p>

I have planned to encrypt a string using a public key which is stored in a database as Blob.I have created method called readBlob() to read the key and save it to the file.

  public static void readBlob(int userid, String filename) throws SQLException, IOException {
      String url = "jdbc:mysql://localhost:3306/bank";
        String user = "root";
        String password = "root";
        String email=null;

            Connection conn = DriverManager.getConnection(url, user, password);
            String sql = "select * from users where user_id=?";
            PreparedStatement statement = conn.prepareStatement(sql);
            statement.setLong(1, userid);
            ResultSet result = statement.executeQuery();
            File file = new File(filename);
            @SuppressWarnings("resource")
            FileOutputStream output = new FileOutputStream(file);
            String keys=null;

    while(result.next()) {
         byte[] buffer = new byte[1];
         InputStream input = result.getBinaryStream("key");
         while (input.read(buffer) > 0) {
             output.write(buffer);
            }        
        }
  }

它确实工作得很好,但是我不需要将其保存到本地文件中,我需要一种无需保存即可读取Blob的方法.

It worked really well but I don't need to save it to the local file ,I need a way to read the Blob without saving it.

推荐答案

您可以使用

以Java编程语言中Blob对象的形式检索此ResultSet对象的当前行中指定列的值.

Retrieves the value of the designated column in the current row of this ResultSet object as a Blob object in the Java programming language.

这篇关于在不保存文件的情况下读取Blob文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆