import com.mysql.jdbc.exceptions.MySQLDataException; import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; /** * Created by roysez on 08.02.2017. */ public class Main2 { public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); // гурхить драйвер в память String userName = "root"; String userPassword = "somepassword"; String dbURL = "jdbc:mysql://localhost/test3"; Connection databaseConnection = DriverManager.getConnection(dbURL,userName,userPassword); PreparedStatement addCVStatement = databaseConnection.prepareStatement("update students SET cv=? where first_name='Sergiy' and last_name='Balukh'"); File pdfFile = new File("C:\\Users\\roysez\\Downloads\\SergiyBalukhCV.pdf"); FileInputStream input = new FileInputStream(pdfFile); addCVStatement.setBinaryStream(1,input,pdfFile.length()); addCVStatement.executeUpdate(); databaseConnection.commit(); }catch (MySQLDataException e ){ e.printStackTrace(); } catch(Exception e){ e.printStackTrace(); } } } 

Mistake

I can not solve the problem in any way, I have found all such topics wrong, nothing helps.

    1 answer 1

    Check your version of mysql-connector, it should be 5.1.x and higher, it seems that in 5.0 the setBinaryStream method is not supported.