I want to add an image to the database.But nothing happens.There is a connection to the database.
AssetManager assManager = getApplicationContext().getAssets();
AssetFileDescriptor assetFileDescriptor = assManager.openFd("k.jpeg");
FileDescriptor fileDescriptor = assetFileDescriptor.getFileDescriptor();
String newPath = path.toString();
Bitmap bitmap = BitmapFactory.decodeStream(ims);
imageView.setImageBitmap(bitmap);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream);
byte[] bytesImage = byteArrayOutputStream.toByteArray();
String encodedImage = Base64.encodeToString(bytesImage, Base64.DEFAULT);
PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO photo(id) VALUES (?)");
FileInputStream fin = new FileInputStream(fileDescriptor);
preparedStatement.setBinaryStream(1, fin);
//Executing the statement
preparedStatement.executeUpdate()
writes an error com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: '\xC5\x01\xB4\xBF\x0D\x00...' for column 'id' at row
preparedStatement.executeUpdate();and then closepreparedStatement