MySQL JDBC insert an Image in a Table - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

MySQL JDBC insert an Image in a Table

Share This



This code snippet is written to insert an image into a table. Hence, first, a table is created with the following schema as shown below. Check that the data type of the photo attribute, blob. The data type blob is used to hold large binary data where the length of the data is variable.

mysql_library_photos_table_struct


Here, the table (photo) is created in library database. Thus, the following code snippet is written to insert an image in this table.

You may try the following code snippet.

1
2
3
4
5
6
7
8
9
10
package com.t4b.jdbc.mysql.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Happy Exploring!

Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.