public class Main {
public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
String userName = "root";
String password = "1";
String connectionUrl = "jdbc:sqlite:D:\\Java_project\\Rabota_s_basami_dannix\\database";
Class.forName("org.sqlite.JDBC");
try(Connection connection = DriverManager.getConnection(connectionUrl);
Statement statement = connection.createStatement()) {
System.out.println("Connection establish");
BufferedImage image = ImageIO.read(new File("img.jpg"));
Blob blob = connection.createBlob();
OutputStream outputStream = blob.setBinaryStream(1);
ImageIO.write(image,"jpg",outputStream);
outputStream.close();
PreparedStatement statement1 = connection.prepareStatement("insert into carblob(name,speed,img) values(?,?,?)");
statement1.setString(1,"BMW");
statement1.setInt(2,200);
statement1.setBlob(3,blob);
statement1.execute();
}
}
}
Вот стэк-трейс исключения:
Exception in thread "main" java.sql.SQLFeatureNotSupportedException
at org.sqlite.jdbc4.JDBC4Connection.createBlob(JDBC4Connection.java:75)
at com.company.Main.main(Main.java:24)
Воспользуйтесь методом setBytes:
try (FileInputStream fileInputStream =
new FileInputStream(
new File("2018-10-17 22_16_32-Best Practices for Sencha Javascript Applications on Vimeo.png"))) {
byte[] bytes = new byte[fileInputStream.available()];
fileInputStream.read(bytes);
System.out.println(bytes.length);
try (PreparedStatement statement1 =
connection.prepareStatement("insert into carblob(name,speed,img) values(?,?,?)");) {
statement1.setString(1, "BMW");
statement1.setInt(2, 200);
statement1.setBytes(3, bytes);
statement1.execute();
}
}
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
Нужен совет по ООП