我使用
将一些图像存储在 MySQL 数据库中ps.setBinaryStream(1, photo);
其中photo
是一个InputStream
。
当我从数据库读取图像时,我需要将其转换为byte[]
。我怎样才能做到这一点?
最佳答案
您需要做的只是一条语句和一个结果集。像这样的事情:
Statement myStatement=(Statement) myConnection.createStatement();
ResultSet myRS=myStatement.executeQuery(mySQLstring);
byte[] photo = myRS.getBytes("myphotoColumnLabel");
关于java - 将 MySql 输入流转换为 byte[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47959510/