Java SQL Blob writeToBlob(int index, PreparedStatement ps, byte[] data)

Here you can find the source of writeToBlob(int index, PreparedStatement ps, byte[] data)

Description

write To Blob

License

Open Source License

Declaration

public static void writeToBlob(int index, PreparedStatement ps, byte[] data) throws SQLException 

Method Source Code

//package com.java2s;
/*//from   w w  w.j a v a  2  s.  co  m
 * Copyright (C) 2010 Francisco Jos? Morero Peyrona. All Rights Reserved.
 *
 * This file is part of Tapas project: http://code.google.com/p/tapas-tpv/
 *
 * GNU Classpath is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the free
 * Software Foundation; either version 3, or (at your option) any later version.
 *
 * Tapas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Tapas; see the file COPYING.  If not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.io.ByteArrayInputStream;

import java.sql.PreparedStatement;

import java.sql.SQLException;

public class Main {
    public static void writeToBlob(int index, PreparedStatement ps, byte[] data) throws SQLException {
        ByteArrayInputStream bais = null;

        if (data != null) {
            bais = new ByteArrayInputStream(data);
        }

        ps.setBinaryStream(index, bais);
    }
}

Related

  1. readBytes(Blob blob, byte[] defaultValue)
  2. safeFree(Blob blob)
  3. safeFree(Blob blob)
  4. toByteArray(Blob blob)
  5. writeStringToBlob(String value, PreparedStatement preparedStatement, int index)