当尝试将Blob从数据库转换为图像时遇到此错误。我曾尝试寻找解决方案,但找不到任何东西。调用时抛出异常:
sampleBlob.getBinaryStream(0, (int) sampleBlob.length())
其余代码:
String sql = "Select * from users where `UserID` = '"+id+"'";
Statement s2 = con.createStatement();
ResultSet studentData = s2.executeQuery(sql);
studentData.next();
Blob imageBlob = studentData.getBlob("Image");
try {
in = imageBlob.getBinaryStream(0, (int) imageBlob.length());
img = ImageIO.read(in);
finalImg = new ImageIcon(img);
} catch (NullPointerException e) {
finalImg = new ImageIcon(getClass().getResource("/default.png"));
}
例外:
java.sql.SQLException: "pos" argument can not be < 1.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861)
at com.mysql.jdbc.Blob.getBinaryStream(Blob.java:340)