Я столкнулся с этой ошибкой при попытке преобразовать большой двоичный объект из базы данных в изображение. Я пытался найти решение, но ничего не смог найти. Исключение выдается при вызове:
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)