Can't insert byte[] into MySQL using java

前端 未结 3 732
夕颜
夕颜 2021-01-13 08:59

Following is the code I have used:

byte[] bkey = key.getEncoded();
String query = \"INSERT INTO keytable (name, key) VALUES (?,?)\";
PreparedStatement pstmt          


        
3条回答
  •  孤街浪徒
    2021-01-13 09:39

    You should add a binary stream. Do you have access to the inputstream ?? like this..

    FileInputStream input = new FileInputStream("myfile.gif");
    String query = "INSERT INTO `keytable` (`name`, `key`) VALUES (?,?)";
    PreparedStatement pstmt = (PreparedStatement) connection.prepareStatement(query);
    pstmt.setString(1, "test");
    pstmt.setBinaryStream(2, input, input.available());
    

提交回复
热议问题