Retrieve File from table by using JDBC with example
To retrieve file from table by using the JDBC here is the example. Let's, come to the first to database as MySQL and table name as myFiles and column name as file_type. These table data we have already inserted files in previous program. Now, we should retrieve from the ResultSet using getClob() method. 1 Clob file = rs . getClob (); Here, getClob() method retrieving data from column and storing it into Clob class object as file. Use getCharacterStream() method which will available under the Clob object, it also gets the file data from Clob object into a reader object. 1 Reader r = file . getCharacterStream (); Here, we are reding data from Reader object r and writing it into FileWriter which stores it into a file as D:/OutPutFile.txt . Registering the Driver and creating Connection and Statements are same in the all JDBC programs. In query we are fetching only file column from table. 1 2 3 4 5 6 7 8 9 10 11