在不保存文件的情况下读取Blob文件 [英] Read Blob file without saving it a file
本文介绍了在不保存文件的情况下读取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.
推荐答案
查看全文