How to store file in MySQL database using JDBC

By | August 2, 2018

In this post we will look into how to store text file/CLOB data in MYSQL database using JDBCIf you are using some other database like Oracle,Sybase or DB2, still process would be similar.Create a folder InputFiles or folder with any name in project home directory as shown in the given screen shot.
After that add three text files:C language.txt,C++ language.txt and Java language.txt Or you can create text files with some text content with any name as per your choice.

Project structure in eclipse:

SQL Query to create storetextfile_table  in MySQL database (jdbcdb schema)
DB.sql

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

Below  ClientTest.java class uses to save three text files(C language.txt,C++ language.txt and Java language.txt)

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

Above console output clearly shows that all three files are saved in MSQL database.

If you query database table storetextfile_table then you will find three records are inserted as below:

That’s all about  how to store file in MySQL database using JDBC

You May Also Like:

How to read files/CLOB data from MySQL database using JDBC
Writing and Reading MySQL BLOB/binary files Using JDBC
ResultSetMetaData in JDBC example
How to get primary key value (auto-generated keys) from inserted queries using JDBC?

If you have any feedback or suggestion please feel free to drop in below comment box. 

Leave a Reply

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