Java SQL Blob writeStringToBlob(String value, PreparedStatement preparedStatement, int index)

Here you can find the source of writeStringToBlob(String value, PreparedStatement preparedStatement, int index)

Description

write String To Blob

License

Apache License

Declaration

public static void writeStringToBlob(String value, PreparedStatement preparedStatement, int index) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

import java.sql.PreparedStatement;

import java.sql.SQLException;

public class Main {
    public static void writeStringToBlob(String value, PreparedStatement preparedStatement, int index) {
        try {/*from  ww  w  .jav a 2s.c  om*/
            final byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
            preparedStatement.setBinaryStream(index, new ByteArrayInputStream(bytes), bytes.length);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. readBlob(Blob blob)
  2. readBytes(Blob blob, byte[] defaultValue)
  3. safeFree(Blob blob)
  4. safeFree(Blob blob)
  5. toByteArray(Blob blob)
  6. writeToBlob(int index, PreparedStatement ps, byte[] data)