How to read files/CLOB Data from MySQL database using JDBC

By | August 2, 2018

In previous post  How to store file in MySQL database using JDBC we learnt how to save text file or CLOB(character large object) data in MYSQL database.In this post we will learn how read it back from database.

If you are using some other database like Oracle,Sybase or DB2, still process would be similar.

Make sure that you have created a folder with name DownLoadFiles in your project home directory as below screen shot.

After reading text file content from database we are going to write in DownLoadFiles folder

Project structure in eclipse:

SQL Query to create storetextfile_table  and insert three rows with column name file_content which contains file text data in MySQL database (jdbcdb schema)
DB.sql

After running above DB Script storetextfile_table will look like as below:

DBUtil.java class which is responsible to connect with MySQL database.

ClientTest.java class uses to read three text files(C language.txt,C++ language.txt and Java language.txt) from database.

After running ClientTest.java program you will look below  output on eclipse console:

Now just refresh your project and expand DownLoadFiles folder you will be three files are downloaded from database and written in this folder as given in below screen shot.

That’s all about  How to read file from MySQL database using JDBC
If you have any feedback or suggestion please feel free to drop in blow comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *