{"id":140733,"date":"2026-01-20T17:41:00","date_gmt":"2026-01-20T15:41:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=140733"},"modified":"2026-01-20T12:16:12","modified_gmt":"2026-01-20T10:16:12","slug":"inserting-blob-using-spring-jdbctemplate-example","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html","title":{"rendered":"Inserting BLOB Using Spring JdbcTemplate Example"},"content":{"rendered":"<h2 class=\"wp-block-heading\">1. Introduction<\/h2>\n<p>BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files. For smaller BLOBs, setting a byte array directly in memory is ok. For large BLOBs, streaming is more memory efficient. In this example, I will demonstrate how to use <a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/jdbc\/core\/JdbcTemplate.html\" target=\"_blank\" rel=\"noreferrer noopener\">JdbcTemplate<\/a> to insert and update a BLOB field in a <a href=\"https:\/\/www.postgresql.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL<\/a> database.<\/p>\n<h2 class=\"wp-block-heading\">2. Setup<\/h2>\n<p>In this step, I will create a Spring Boot (4.0.1) Java (21) project via <a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Spring Initializer<\/a> with <a href=\"https:\/\/mvnrepository.com\/artifact\/org.postgresql\/postgresql\" target=\"_blank\" rel=\"noreferrer noopener\">PostgreSQL<\/a>, <a href=\"https:\/\/mvnrepository.com\/artifact\/org.projectlombok\/lombok\" target=\"_blank\" rel=\"noreferrer noopener\">Lombok<\/a>, and <a href=\"https:\/\/mvnrepository.com\/artifact\/org.springframework.boot\/spring-boot-starter-data-jpa\" target=\"_blank\" rel=\"noreferrer noopener\">JPA <\/a>dependencies.<\/p>\n<h3 class=\"wp-block-heading\">2.1 Build.gradle<\/h3>\n<p>Here is the generated <code>build.gradle<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>build.gradle<\/em><\/span><\/p>\n<pre class=\"brush:plain\">plugins {\n\tid 'java'\n\tid 'org.springframework.boot' version '4.0.1'\n\tid 'io.spring.dependency-management' version '1.1.7'\n}\n\ngroup = 'org.jcg.zheng.demo'\nversion = '0.0.1-SNAPSHOT'\ndescription = 'Demo project for BLOB'\n\njava {\n\ttoolchain {\n\t\tlanguageVersion = JavaLanguageVersion.of(21)\n\t}\n}\n\nrepositories {\n\tmavenCentral()\n}\n\ndependencies {\n\timplementation 'org.springframework.boot:spring-boot-starter-data-jpa'\n  \tcompileOnly 'org.projectlombok:lombok'\n  \truntimeOnly 'org.postgresql:postgresql'\n  \tannotationProcessor 'org.projectlombok:lombok'\n \ttestImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'\n \ttestRuntimeOnly 'org.junit.platform:junit-platform-launcher'\n}\n\ntasks.named('test') {\n\tuseJUnitPlatform()\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">2.2 InsertBlobApplication<\/h3>\n<p>Here is the generated <code>InsertBlobApplication.java<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>InsertBlobApplication.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package org.jcg.zheng.demo.insert_blob;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class InsertBlobApplication {\n\n\tpublic static void main(String[] args) {\n\t\tSpringApplication.run(InsertBlobApplication.class, args);\n\t}\n\n}\n<\/pre>\n<h3 class=\"wp-block-heading\">2.3 Application Properties<\/h3>\n<p>Here is the updated <code>application.properties<\/code> file.<\/p>\n<p><span style=\"text-decoration: underline\"><em>application.properties<\/em><\/span><\/p>\n<pre class=\"brush:plain;highlight:[9,10]\">spring.application.name=insert-blob\n\n# DataSource configuration\nspring.datasource.url=jdbc:postgresql:\/\/localhost:5432\/postgres?currentSchema=marydb\nspring.datasource.username=postgres\nspring.datasource.password=\nspring.datasource.driver-class-name=org.postgresql.Driver\n\nlogging.level.org.springframework.jdbc.core.JdbcTemplate=trace\nlogging.level.org.springframework.jdbc.core.StatementCreatorUtils=trace\n\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 9-10: enable the logging to show the raw SQL statement and binding parameters.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">2.4 Start the Spring Boot Application<\/h3>\n<p>In this step, I will start the generated spring boot application and capture the server log.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Server Log<\/em><\/span><\/p>\n<pre class=\"brush:plain;highlight:[21]\">\n  .   ____          _            __ _ _\n \/\\\\ \/ ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\\/ _` | \\ \\ \\ \\\n \\\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | \/ \/ \/ \/\n =========|_|==============|___\/=\/_\/_\/_\/\n\n :: Spring Boot ::                (v4.0.1)\n\n2026-01-16T20:32:26.077-06:00  INFO 2864 --- [insert-blob] [           main] o.j.z.d.i.InsertBlobApplication          : Starting InsertBlobApplication using Java 21.0.8 with PID 2864 (C:\\MaryZheng\\workspace\\insert-blob-postgre\\bin\\main started by zzhen in C:\\MaryZheng\\workspace\\insert-blob-postgre)\n2026-01-16T20:32:26.081-06:00  INFO 2864 --- [insert-blob] [           main] o.j.z.d.i.InsertBlobApplication          : No active profile set, falling back to 1 default profile: \"default\"\n2026-01-16T20:32:26.440-06:00  INFO 2864 --- [insert-blob] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.\n2026-01-16T20:32:26.456-06:00  INFO 2864 --- [insert-blob] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10 ms. Found 0 JPA repository interfaces.\n2026-01-16T20:32:26.617-06:00  INFO 2864 --- [insert-blob] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...\n2026-01-16T20:32:26.844-06:00  INFO 2864 --- [insert-blob] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@64f16277\n2026-01-16T20:32:26.846-06:00  INFO 2864 --- [insert-blob] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.\n2026-01-16T20:32:26.942-06:00  INFO 2864 --- [insert-blob] [           main] org.hibernate.orm.jpa                    : HHH008540: Processing PersistenceUnitInfo [name: default]\n2026-01-16T20:32:27.012-06:00  INFO 2864 --- [insert-blob] [           main] org.hibernate.orm.core                   : HHH000001: Hibernate ORM core version 7.2.0.Final\n2026-01-16T20:32:27.535-06:00  INFO 2864 --- [insert-blob] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer\n2026-01-16T20:32:27.592-06:00  INFO 2864 --- [insert-blob] [           main] org.hibernate.orm.connections.pooling    : HHH10001005: Database info:\n\tDatabase JDBC URL [jdbc:postgresql:\/\/localhost:5432\/postgres?currentSchema=marydb]\n\tDatabase driver: PostgreSQL JDBC Driver\n\tDatabase dialect: PostgreSQLDialect\n\tDatabase version: 18.0\n\tDefault catalog\/schema: postgres\/marydb\n\tAutocommit mode: undefined\/unknown\n\tIsolation level: READ_COMMITTED [default READ_COMMITTED]\n\tJDBC fetch size: none\n\tPool: DataSourceConnectionProvider\n\tMinimum pool size: undefined\/unknown\n\tMaximum pool size: undefined\/unknown\n2026-01-16T20:32:28.238-06:00  INFO 2864 --- [insert-blob] [           main] org.hibernate.orm.core                   : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)\n2026-01-16T20:32:28.246-06:00  INFO 2864 --- [insert-blob] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'\n2026-01-16T20:32:28.436-06:00  INFO 2864 --- [insert-blob] [           main] o.j.z.d.i.InsertBlobApplication          : Started InsertBlobApplication in 2.647 seconds (process running for 2.928)\n2026-01-16T20:32:28.446-06:00  INFO 2864 --- [insert-blob] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'\n2026-01-16T20:32:28.449-06:00  INFO 2864 --- [insert-blob] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...\n2026-01-16T20:32:28.452-06:00  INFO 2864 --- [insert-blob] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 21: shows the Spring boot application using the PostgreSQL database as the configuration file specified.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">3. PostgreSQL Database Table with a BLOB Column<\/h2>\n<p>In this step, I will create a table with a BLOB column in a PostgreSQL database:<\/p>\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/table.jpg\"><img decoding=\"async\" width=\"778\" height=\"296\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/table.jpg\" alt=\"spring jdbctemplate insert blob\" class=\"wp-image-140801\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/table.jpg 778w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/table-300x114.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/table-768x292.jpg 768w\" sizes=\"(max-width: 778px) 100vw, 778px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 1. Demo_BLOB_Table<\/figcaption><\/figure>\n<\/div>\n<p><span style=\"text-decoration: underline\"><em>Create Table SQL<\/em><\/span><\/p>\n<pre class=\"brush:sql;highlight:[4]\"> create table demo_blob_table (\n        id integer not null,\n        content_type varchar(255),\n        blob_col bytea,\n        primary key (id)\n    );<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 4: The PostgreSQL <a href=\"https:\/\/www.w3resource.com\/PostgreSQL\/snippets\/postgresql-bytea-explained.php#google_vignette\" target=\"_blank\" rel=\"noreferrer noopener\">bytea<\/a> data type is used to map to a BLOB object.<\/li>\n<li><strong>Note<\/strong>: use different storage systems when a <code>bytea<\/code> field exceeds 1 GB.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">3.1 Create a Java Entity<\/h3>\n<p>In this example, I will create the <code>BlobMeta.java<\/code> that maps to a database table for non-BLOB fields.<\/p>\n<p><span style=\"text-decoration: underline\"><em>BlobMeta.java<\/em><\/span><\/p>\n<pre class=\"brush:java;highlight:[9]\">package org.jcg.zheng.demo.insert_blob.entity;\n\nimport jakarta.persistence.Entity;\nimport jakarta.persistence.Id;\nimport jakarta.persistence.Table;\nimport lombok.Data;\n\n@Entity\n@Table(name=\"demo_blob_table\")\n@Data\npublic class BlobMeta {\n\t\n\t@Id\n\tprivate Integer id;\n\tprivate String contentType;\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 9: the <code>BlobMeta<\/code> entity is mapped to table <code>demo_blob_table<\/code> without BLOB fields to reduce memory usage as JPA caches objects in memory.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">4. Spring JdbcTemplate Insert BLOB<\/h2>\n<p>In this step, I will create an <code>InsertBlobService.java<\/code> that inserts or updates a BLOB column with the following methods:<\/p>\n<ul class=\"wp-block-list\">\n<li><code>insert_with_ByteArray<\/code>: insert a BLOB as <code>byte[]<\/code> directly using Spring JDBC. <\/li>\n<li><code>insert_with_bytes<\/code>: insert a BLOB with the <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.sql\/java\/sql\/PreparedStatement.html#setBytes(int,byte%5B%5D)\" target=\"_blank\" rel=\"noreferrer noopener\">setBytes<\/a>() method that sets the designated parameter to the given Java array of bytes when BLOB data is less than 1 MB.<\/li>\n<li><code>insert_with_BinaryStream<\/code>: insert a BLOB and use the <a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.sql\/java\/sql\/PreparedStatement.html#setBinaryStream(int,java.io.InputStream,int)\" target=\"_blank\" rel=\"noreferrer noopener\">setBinaryStream<\/a> method to set the designated parameter to the given input stream. It&#8217;s good when BLOB data is greater than 1 MB and less than 1 GB.<\/li>\n<li><code>insert_with_SQLVarbinary<\/code>: insert a BLOB using Spring JDBC, explicitly treating the bytes array as <a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/jdbc\/core\/SqlParameterValue.html\">SqlParameterValue<\/a>(<a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/sql\/Types.html#LONGVARBINARY\" target=\"_blank\" rel=\"noreferrer noopener\">Types.VARBINARY<\/a>) so the database stores it correctly.<\/li>\n<li><code>readBlob_asObject<\/code>: read a BLOB via the <code>JdbcTemplate.queryForObject<\/code> method. The return data is in memory. it&#8217;s ok for smaller BLOB objects.<\/li>\n<li><code>readBlob_asStream<\/code>: read a BLOB via the <code>JdbcTemplate.queryForStream<\/code> method. It streams into the <code>InputStream<\/code> and then writes to a file. It&#8217;s more memory efficient.<\/li>\n<li><code>update_with_bytes<\/code>: update a BLOC via the <code>setBytes<\/code> method.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>InsertBlobService.java<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java;highlight:[25,26,27,37,42,50,60,66,71,75,76,88]\">package org.jcg.zheng.demo.insert_blob.service;\n\nimport java.io.ByteArrayInputStream;\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.nio.file.Paths;\nimport java.nio.file.StandardCopyOption;\nimport java.sql.PreparedStatement;\nimport java.sql.Types;\nimport java.util.stream.Stream;\n\nimport org.jcg.zheng.demo.insert_blob.entity.BlobMeta;\nimport org.springframework.jdbc.core.JdbcTemplate;\nimport org.springframework.jdbc.core.SqlParameterValue;\nimport org.springframework.stereotype.Service;\n\nimport jakarta.transaction.Transactional;\n\n@Service\n@Transactional\npublic class InsertBlobService {\n\n\tprivate static final String SELECT_BLOB_SQL = \"SELECT blob_col from demo_blob_table WHERE id=?\";\n\tprivate static final String UPDATE_BLOB_SQL = \"UPDATE demo_blob_table set blob_col=? WHERE id=?\";\n\tprivate static final String INSERT_BLOB_SQL = \"INSERT INTO demo_blob_table(id, content_type, blob_col) VALUES (?,?,?)\";\n\n\tprivate final JdbcTemplate jdbcTemplate;\n\n\tpublic InsertBlobService(JdbcTemplate jdbcTemplate) {\n\t\tsuper();\n\t\tthis.jdbcTemplate = jdbcTemplate;\n\t}\n\n\tpublic void insert_with_ByteArray(BlobMeta blobMeta, byte[] data) {\n\t\tjdbcTemplate.update(INSERT_BLOB_SQL, blobMeta.getId(), blobMeta.getContentType(), data);\n\t}\n\n\tpublic void insert_with_SQLVarbinary(BlobMeta blobMeta, byte[] data) {\n\t\tjdbcTemplate.update(INSERT_BLOB_SQL, blobMeta.getId(), blobMeta.getContentType(),\n\t\t\t\tnew SqlParameterValue(Types.VARBINARY, data));\n\t}\n\n\tpublic void insert_with_BinaryStream(BlobMeta blobMeta, byte[] data) {\n\t\tjdbcTemplate.update(con -&gt; {\n\t\t\tPreparedStatement ps = con.prepareStatement(INSERT_BLOB_SQL);\n\t\t\tps.setInt(1, blobMeta.getId());\n\t\t\tps.setString(2, blobMeta.getContentType());\n\t\t\tps.setBinaryStream(3, new ByteArrayInputStream(data));\n\t\t\treturn ps;\n\t\t});\n\t}\n\n\tpublic void insert_with_bytes(BlobMeta blobMeta, byte[] data) {\n\t\tjdbcTemplate.update(con -&gt; {\n\t\t\tPreparedStatement ps = con.prepareStatement(INSERT_BLOB_SQL);\n\t\t\tps.setInt(1, blobMeta.getId());\n\t\t\tps.setString(2, blobMeta.getContentType());\n\t\t\tps.setBytes(3, data);\n\t\t\treturn ps;\n\t\t});\n\t}\n\n\tpublic byte[] readBlob_asObject(int id) {\n\t\treturn jdbcTemplate.queryForObject(SELECT_BLOB_SQL, byte[].class, id);\n\t}\n\n\tpublic void readBlob_asStream(int id) {\n\t\tPath target = Paths.get(\"output.bin\");\n\t\ttry (Stream&lt;InputStream&gt; stream = jdbcTemplate.queryForStream(SELECT_BLOB_SQL,\n\t\t\t\t(rs, rowNum) -&gt; rs.getBinaryStream(\"blob_col\"), id)) {\n\t\t\tstream.findFirst().ifPresent(inputStream -&gt; {\n\n\t\t\t\ttry (InputStream in = inputStream) {\n\t\t\t\t\tFiles.copy(in, target, StandardCopyOption.REPLACE_EXISTING);\n\t\t\t\t} catch (IOException e) {\n\t\t\t\t\te.printStackTrace();\n\t\t\t\t}\n\t\t\t});\n\n\t\t}\n\n\t}\n\n\tpublic void update_with_bytes(int id, byte[] data) {\n\t\tjdbcTemplate.update(UPDATE_BLOB_SQL, ps -&gt; {\n\t\t\tps.setBytes(1, data);\n\t\t\tps.setInt(2, id);\n\t\t});\n\t}\n\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line 25-27: the raw SQL statements to insert, update, and select BLOB data.<\/li>\n<li>Line 37: map <code>byte[]<\/code> directly in the <code>insert<\/code> statement.<\/li>\n<li>Line 42: use <code>SqlParameterValue(Types.VARBINARY)<\/code> to map to <code>byte[]<\/code> to ensure correct JDBC type and avoid JDBC driver-specific issues. It prevents binary data being treated as VARCHAR and works across databases ( MySQL, SQL Server, Oracle, PostgreSQL).<\/li>\n<li>Line 50: <code>setBinaryStream<\/code> maps to <code>InputStream<\/code> for streaming into the database.<\/li>\n<li>Line 60: use <code>setBytes<\/code> maps to <code>byte[]<\/code>.<\/li>\n<li>Line 66: <code>queryForObject<\/code> maps to <code>byte[]<\/code> in memory.<\/li>\n<li>Line 71: <code>queryForStream<\/code> maps to <code>InputStream<\/code>.<\/li>\n<li>Line 75: <code>try-with-resources<\/code> clause closes <code>InputStream<\/code> explicitly.<\/li>\n<li>Line 76: <code>Files.copy<\/code> writes the BLOB into a file.<\/li>\n<li>Line 88: <code>setBytes<\/code> is used in an update statement.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">5. Test InsertBlobService<\/h2>\n<p>In this step, I will create a <code>InsertBlobServiceTest.java<\/code> that tests the methods to insert, update, and select a BLOB column.<\/p>\n<p><span style=\"text-decoration: underline\"><em>InsertBlobServiceTest.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package org.jcg.zheng.demo.insert_blob.service;\n\nimport static org.junit.jupiter.api.Assertions.assertEquals;\n\nimport org.jcg.zheng.demo.insert_blob.entity.BlobMeta;\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.context.SpringBootTest;\n\n@SpringBootTest\nclass InsertBlobServiceTest {\n\n\tprivate static final String BLOB_STRING = \"this is blob\";\n\tprivate static final String BLOB_STRING_2 = \"this is blob 2\";\n\t@Autowired\n\tprivate InsertBlobService testClass;\n\n\t@Test\n\tvoid test_insert_with_BinaryStream() {\n\t\tint test_id = 2;\n\n\t\ttestClass.insert_with_BinaryStream(testBlobMeta(test_id), BLOB_STRING.getBytes());\n\n\t\tbyte[] ret = testClass.readBlob_asObject(test_id);\n\n\t\tassertEquals(BLOB_STRING, new String(ret));\n\n\t}\n\n\t@Test\n\tvoid test_insert_with_ByteArray() {\n\t\tint test_id = 1;\n\n\t\ttestClass.insert_with_ByteArray(testBlobMeta(test_id), BLOB_STRING.getBytes());\n\n\t\tbyte[] ret = testClass.readBlob_asObject(test_id);\n\n\t\tassertEquals(BLOB_STRING, new String(ret));\n\t\n\t\ttestClass.readBlob_asStream(1);\n\n\t}\n\n\t@Test\n\tvoid test_insert_with_bytes() {\n\t\tint test_id = 3;\n\n\t\ttestClass.insert_with_bytes(testBlobMeta(test_id), BLOB_STRING.getBytes());\n\n\t\tbyte[] ret = testClass.readBlob_asObject(test_id);\n\n\t\tassertEquals(BLOB_STRING, new String(ret));\n\n\t}\n\n\t@Test\n\tvoid test_insert_with_SQLVarbinary() {\n\t\tint test_id = 4;\n\n\t\ttestClass.insert_with_SQLVarbinary(testBlobMeta(test_id), BLOB_STRING.getBytes());\n\n\t\tbyte[] ret = testClass.readBlob_asObject(test_id);\n\n\t\tassertEquals(BLOB_STRING, new String(ret));\n\n\t}\n\n\t\n\t@Test\n\tvoid test_update_with_bytes() {\n\t\tint test_id = 1;\n\t\tbyte[] ret = testClass.readBlob_asObject(test_id);\n\t\tif (ret == null) {\n\t\t\ttestClass.insert_with_ByteArray(testBlobMeta(test_id), BLOB_STRING.getBytes());\n\t\t}\n\n\t\ttestClass.update_with_bytes(1, BLOB_STRING_2.getBytes());\n\n\t\tassertEquals(BLOB_STRING_2, new String(testClass.readBlob_asObject(1)));\n\n\t}\n\n\tprivate BlobMeta testBlobMeta(int id) {\n\t\tBlobMeta blobMeta = new BlobMeta();\n\t\tblobMeta.setId(id);\n\t\tblobMeta.setContentType(\"txt\");\n\t\treturn blobMeta;\n\t}\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n<p>Run tests and capture output. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/test.jpg\"><img decoding=\"async\" width=\"432\" height=\"325\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/test.jpg\" alt=\"spring jdbctemplate insert blob\" class=\"wp-image-140802\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/test.jpg 432w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/test-300x226.jpg 300w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/a><figcaption class=\"wp-element-caption\">Figure 2. Unit Tests<\/figcaption><\/figure>\n<\/div>\n<p>The console log shows the actual SQL statements and the binding parameters.<\/p>\n<p><span style=\"text-decoration: underline\"><em>InsertBlobServiceTest Console Log<\/em><\/span><\/p>\n<pre class=\"brush:plain\">20:36:30.695 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [org.jcg.zheng.demo.insert_blob.service.InsertBlobServiceTest]: InsertBlobServiceTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.\n20:36:30.773 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration org.jcg.zheng.demo.insert_blob.InsertBlobApplication for test class org.jcg.zheng.demo.insert_blob.service.InsertBlobServiceTest\n\n  .   ____          _            __ _ _\n \/\\\\ \/ ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\\/ _` | \\ \\ \\ \\\n \\\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | \/ \/ \/ \/\n =========|_|==============|___\/=\/_\/_\/_\/\n\n :: Spring Boot ::                (v4.0.1)\n\n2026-01-16T20:36:31.076-06:00  INFO 26912 --- [insert-blob] [           main] o.j.z.d.i.service.InsertBlobServiceTest  : Starting InsertBlobServiceTest using Java 21.0.8 with PID 26912 (started by zzhen in C:\\MaryZheng\\workspace\\insert-blob-postgre)\n2026-01-16T20:36:31.076-06:00  INFO 26912 --- [insert-blob] [           main] o.j.z.d.i.service.InsertBlobServiceTest  : No active profile set, falling back to 1 default profile: \"default\"\n2026-01-16T20:36:31.322-06:00  INFO 26912 --- [insert-blob] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.\n2026-01-16T20:36:31.339-06:00  INFO 26912 --- [insert-blob] [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.\n2026-01-16T20:36:31.520-06:00  INFO 26912 --- [insert-blob] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...\n2026-01-16T20:36:31.696-06:00  INFO 26912 --- [insert-blob] [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@31f295b6\n2026-01-16T20:36:31.697-06:00  INFO 26912 --- [insert-blob] [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.\n2026-01-16T20:36:31.778-06:00  INFO 26912 --- [insert-blob] [           main] org.hibernate.orm.jpa                    : HHH008540: Processing PersistenceUnitInfo [name: default]\n2026-01-16T20:36:31.842-06:00  INFO 26912 --- [insert-blob] [           main] org.hibernate.orm.core                   : HHH000001: Hibernate ORM core version 7.2.0.Final\n2026-01-16T20:36:32.239-06:00  INFO 26912 --- [insert-blob] [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer\n2026-01-16T20:36:32.327-06:00  INFO 26912 --- [insert-blob] [           main] org.hibernate.orm.connections.pooling    : HHH10001005: Database info:\n\tDatabase JDBC URL [jdbc:postgresql:\/\/localhost:5432\/postgres?currentSchema=marydb]\n\tDatabase driver: PostgreSQL JDBC Driver\n\tDatabase dialect: PostgreSQLDialect\n\tDatabase version: 18.0\n\tDefault catalog\/schema: postgres\/marydb\n\tAutocommit mode: undefined\/unknown\n\tIsolation level: READ_COMMITTED [default READ_COMMITTED]\n\tJDBC fetch size: none\n\tPool: DataSourceConnectionProvider\n\tMinimum pool size: undefined\/unknown\n\tMaximum pool size: undefined\/unknown\n2026-01-16T20:36:32.899-06:00  INFO 26912 --- [insert-blob] [           main] org.hibernate.orm.core                   : HHH000489: No JTA platform available (set 'hibernate.transaction.jta.platform' to enable JTA platform integration)\n2026-01-16T20:36:32.905-06:00  INFO 26912 --- [insert-blob] [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'\n2026-01-16T20:36:33.074-06:00  INFO 26912 --- [insert-blob] [           main] o.j.z.d.i.service.InsertBlobServiceTest  : Started InsertBlobServiceTest in 2.187 seconds (process running for 3.087)\nMockito is currently self-attaching to enable the inline-mock-maker. This will no longer work in future releases of the JDK. Please add Mockito as an agent to your build as described in Mockito's documentation: https:\/\/javadoc.io\/doc\/org.mockito\/mockito-core\/latest\/org.mockito\/org\/mockito\/Mockito.html#0.3\nWARNING: A Java agent has been loaded dynamically (C:\\Users\\zzhen\\.gradle\\caches\\modules-2\\files-2.1\\net.bytebuddy\\byte-buddy-agent\\1.17.8\\f09415827a71be7ed621c7bd02550678f28bc81c\\byte-buddy-agent-1.17.8.jar)\nWARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning\nWARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information\nWARNING: Dynamic loading of agents will be disallowed by default in a future release\nOpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended\n2026-01-16T20:36:33.443-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update\n2026-01-16T20:36:33.443-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT INTO demo_blob_table(id, content_type, blob_col) VALUES (?,?,?)]\n2026-01-16T20:36:33.450-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [4], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.450-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 2, parameter value [txt], value class [java.lang.String], SQL type unknown\n2026-01-16T20:36:33.451-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 3, parameter value [[B@2604940], value class [[B], SQL type -3\n2026-01-16T20:36:33.453-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows\n2026-01-16T20:36:33.461-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.463-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.463-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [4], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.473-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update\n2026-01-16T20:36:33.473-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement\n2026-01-16T20:36:33.473-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows\n2026-01-16T20:36:33.477-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.477-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.477-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [3], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.480-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update\n2026-01-16T20:36:33.480-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [INSERT INTO demo_blob_table(id, content_type, blob_col) VALUES (?,?,?)]\n2026-01-16T20:36:33.480-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.480-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 2, parameter value [txt], value class [java.lang.String], SQL type unknown\n2026-01-16T20:36:33.480-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 3, parameter value [[B@c8ed958], value class [[B], SQL type unknown\n2026-01-16T20:36:33.481-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows\n2026-01-16T20:36:33.482-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.482-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.482-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.484-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.484-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.489-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.489-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.489-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.490-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update\n2026-01-16T20:36:33.490-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [UPDATE demo_blob_table set blob_col=? WHERE id=?]\n2026-01-16T20:36:33.491-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows\n2026-01-16T20:36:33.492-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.492-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.492-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [1], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.495-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL update\n2026-01-16T20:36:33.495-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement\n2026-01-16T20:36:33.496-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : SQL update affected 1 rows\n2026-01-16T20:36:33.496-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL query\n2026-01-16T20:36:33.496-06:00 DEBUG 26912 --- [insert-blob] [           main] o.s.jdbc.core.JdbcTemplate               : Executing prepared SQL statement [SELECT blob_col from demo_blob_table WHERE id=?]\n2026-01-16T20:36:33.497-06:00 TRACE 26912 --- [insert-blob] [           main] o.s.jdbc.core.StatementCreatorUtils      : Setting SQL statement parameter value: column index 1, parameter value [2], value class [java.lang.Integer], SQL type unknown\n2026-01-16T20:36:33.505-06:00  INFO 26912 --- [insert-blob] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'\n2026-01-16T20:36:33.507-06:00  INFO 26912 --- [insert-blob] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...\n2026-01-16T20:36:33.512-06:00  INFO 26912 --- [insert-blob] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.\n<\/pre>\n<h2 class=\"wp-block-heading\">6. Conclusion<\/h2>\n<p>In this example, I demonstrated several ways to insert, update, and select a BLOB field in the PostgreSQL database.<\/p>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.sql\/java\/sql\/PreparedStatement.html#setBytes(int,byte%5B%5D)\" target=\"_blank\" rel=\"noreferrer noopener\">PreparedStatement.setBytes<\/a>: sets the designated parameter to the given Java array of bytes. It&#8217;s good when BLOB data is less than 1 MB.<\/li>\n<li><a href=\"https:\/\/docs.oracle.com\/en\/java\/javase\/21\/docs\/api\/java.sql\/java\/sql\/PreparedStatement.html#setBinaryStream(int,java.io.InputStream,int)\" target=\"_blank\" rel=\"noreferrer noopener\">PreparedStatement.setBinaryStream<\/a>: sets the designated parameter to the given input stream. It&#8217;s good when BLOB data is greater than 1 MB and less than 1 GB.<\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/jdbc\/core\/SqlParameterValue.html\">SqlParameterValue<\/a>(<a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/sql\/Types.html#LONGVARBINARY\" target=\"_blank\" rel=\"noreferrer noopener\">Types.VARBINARY<\/a>): sets an SQL parameter value for BLOB to avoid JDBC driver issues.<\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-framework\/docs\/current\/javadoc-api\/org\/springframework\/jdbc\/core\/JdbcTemplate.html#queryForStream(java.lang.String,org.springframework.jdbc.core.PreparedStatementSetter,org.springframework.jdbc.core.RowMapper)\" target=\"_blank\" rel=\"noreferrer noopener\">JdbcTemplate.queryForStream<\/a>: read result as Stream for BLOB for better memory management.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">7. Download<\/h2>\n<p>This was an example of inserting BLOB fields via Spring <code>JdbcTemplate<\/code>.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2026\/01\/insert-blob-postgre.zip\"><strong>Inserting BLOB Using Spring JdbcTemplate Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files. For smaller BLOBs, setting a byte array directly in memory is ok. For large BLOBs, streaming is more memory efficient. In this example, I will demonstrate how to use JdbcTemplate &hellip;<\/p>\n","protected":false},"author":128892,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[5015],"class_list":["post-140733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-jdbctemplate"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-20T15:41:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\"},\"headline\":\"Inserting BLOB Using Spring JdbcTemplate Example\",\"datePublished\":\"2026-01-20T15:41:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html\"},\"wordCount\":682,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"JdbcTemplate\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html\",\"name\":\"Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2026-01-20T15:41:00+00:00\",\"description\":\"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/inserting-blob-using-spring-jdbctemplate-example.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Inserting BLOB Using Spring JdbcTemplate Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/33e795ab61de7fab61ed89b4de1668f5\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2024\\\/04\\\/cropped-Mary-Zheng-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.\",\"sameAs\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/mary-zheng\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks","description":"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html","og_locale":"en_US","og_type":"article","og_title":"Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks","og_description":"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.","og_url":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2026-01-20T15:41:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html"},"author":{"name":"Mary Zheng","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5"},"headline":"Inserting BLOB Using Spring JdbcTemplate Example","datePublished":"2026-01-20T15:41:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html"},"wordCount":682,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["JdbcTemplate"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html","url":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html","name":"Inserting BLOB Using Spring JdbcTemplate Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2026-01-20T15:41:00+00:00","description":"1. Introduction BLOB (Binary Large Object) is a large object data type in the database system. BLOB could store documents, images, audio, or video files.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/inserting-blob-using-spring-jdbctemplate-example.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Inserting BLOB Using Spring JdbcTemplate Example"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/33e795ab61de7fab61ed89b4de1668f5","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-Mary-Zheng-96x96.jpg","caption":"Mary Zheng"},"description":"Mary graduated from the Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She worked as a lead Software Engineer where she led and worked with others to design, implement, and monitor the software solution.","sameAs":["https:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/mary-zheng"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/140733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/128892"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=140733"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/140733\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=140733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=140733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=140733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}