Store CLOBs data into database? : Blob Binary Data JDBC « Database SQL JDBC « Java






Store CLOBs data into database?

  

import java.io.File;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Main {
  private static String url = "jdbc:oracle:thin:@localhost:1521:xe";

  private static String username = "yourDatabase";

  private static String password = "welcome";

  public static void main(String[] args) throws Exception {

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(url, username, password);
    conn.setAutoCommit(false);

    String sql = "INSERT INTO documents (name, description, data) VALUES (?, ?, ?)";
    PreparedStatement stmt = conn.prepareStatement(sql);
    stmt.setString(1, "a.txt");
    stmt.setString(2, "b");

    File data = new File("C:\\a.txt");
    FileReader reader = new FileReader(data);
    stmt.setCharacterStream(3, reader, (int) data.length());
    stmt.execute();

    conn.commit();
    reader.close();
    conn.close();

  }
}

   
    
  








Related examples in the same category

1.Read BLOBs data from database
2.Store BLOBs data into database
3.Insert picture to MySQL
4.Demo Display Binary Data From Database
5.Materialize binary data onto client
6.Blob: JDBC deals with Binary Data
7.Inserting Image in Database Table
8.Blob and JDBC: Image
9.Blob: Image 2
10.Blob: image 3
11.Insert an Image
12.Retrieve an Image
13.Store and retrieve an object from a table
14.Read CLOBs data from database
15.Getting BLOB Data from a Database Table: how to retrieves bytes from a BLOB.
16.Getting and Inserting Binary Data into an Database Table