Storing File in Oracle Database Using JDBC

Last Updated : 9 Apr 2026

Storing files in a database is useful when you want to keep documents, text, or large data securely inside the database. In Oracle, this is done using special data types like CLOB.

In this chapter, you will learn how to store a file in an Oracle database using JDBC and the PreparedStatement interface.

What is Storing File in Database?

Storing a file in a database means saving file content (like text or documents) into a table column. For text-based files, Oracle uses the CLOB (Character Large Object) data type.

Required Table Structure

To store a file, first create a table with a CLOB column.

The setCharacterStream() Method

The setCharacterStream() method of PreparedStatement is used to store character data (like text files) into the database.

Syntax

Use the following syntax when you do not know the size (length) of the file in advance. It simply reads the data from the stream and stores it.

Use the following syntax when you know the exact size of the file. This helps in better performance and efficient handling of large data.

This method sets the file data to the specified parameter index.

Example to Store File in Oracle Database

The following example demonstrates how to store a text file into an Oracle database.

Output:

1 records affected

Explanation:

This example reads a text file and stores its content into the database using a CLOB column. The file is read using FileReader and passed to the database using setCharacterStream().