import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; public class ByteArrayToBlob { public static void main (String[] args) { byte [] byteArray = new byte []{ 1 , 2 , 3 , 4 , 5 }; try ( Connection conn = getConnection(); PreparedStatement stmt = conn.prepareStatement( "insert into table_name (column_name) values (?)" )) { Blob blob = conn.createBlob(); blob.setBytes( 1 , byteArray); stmt.setBlob( 1 , blob); stmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); private static Connection getConnection () throws SQLException { // 这里可以使用你喜欢的数据库连接方式 return null ;
  •