{"id":3510,"date":"2015-05-17T05:43:55","date_gmt":"2015-05-17T13:43:55","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3510"},"modified":"2024-01-11T02:27:52","modified_gmt":"2024-01-11T09:27:52","slug":"writing-and-reading-mysql-blob-using-jdbc","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/","title":{"rendered":"Writing and Reading MySQL BLOB Using JDBC"},"content":{"rendered":"\n<p><strong>Summary<\/strong>:\u00a0in this tutorial, you will learn how to write and read MySQL BLOB data using JDBC.<\/p>\n\n\n\n<p class=\"note\">This tutorial picks up where the <a href=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/calling-mysql-stored-procedures-from-jdbc\/\">Calling MySQL Stored Procedures from the JDBC<\/a> tutorial left off.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding a BLOB column to the candidates table<\/h2>\n\n\n\n<p>We&#8217;ll use the <code>candidates<\/code> table in the <code>mysqljdbc<\/code> database for the demonstration.<\/p>\n\n\n\n<p>First, <a href=\"https:\/\/www.mysqltutorial.org\/getting-started-with-mysql\/connect-to-mysql-server\/\">connect to the MySQL server<\/a>:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">mysql -u root -p<\/code><\/span><\/pre>\n\n\n<p>Second, show the structure of the <code>candidates<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">+------------+--------------+------+-----+---------+----------------+\n| Field      | Type         | <span class=\"hljs-keyword\">Null<\/span> | Key | <span class=\"hljs-keyword\">Default<\/span> | Extra          |\n+------------+--------------+------+-----+---------+----------------+\n| id         | int          | NO   | PRI | <span class=\"hljs-keyword\">NULL<\/span>    | auto_increment |\n| first_name | varchar(<span class=\"hljs-number\">50<\/span>)  | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| last_name  | varchar(<span class=\"hljs-number\">50<\/span>)  | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| dob        | date         | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| phone      | varchar(<span class=\"hljs-number\">20<\/span>)  | YES  |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| email      | varchar(<span class=\"hljs-number\">100<\/span>) | YES  |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n+------------+--------------+------+-----+---------+----------------+\n<span class=\"hljs-number\">6<\/span> rows in set (<span class=\"hljs-number\">0.03<\/span> sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-add-column\/\">add a new column<\/a> called <code>resume<\/code> to the <code>candidates<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">ALTER<\/span> <span class=\"hljs-keyword\">TABLE<\/span> candidates \n<span class=\"hljs-keyword\">ADD<\/span> <span class=\"hljs-keyword\">COLUMN<\/span> <span class=\"hljs-keyword\">resume<\/span> LONGBLOB\n<span class=\"hljs-literal\">NULL<\/span> <span class=\"hljs-keyword\">AFTER<\/span> email;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, display the structure of the <code>candidates<\/code> table to verify the change:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">+------------+--------------+------+-----+---------+----------------+\n| Field      | Type         | <span class=\"hljs-keyword\">Null<\/span> | Key | <span class=\"hljs-keyword\">Default<\/span> | Extra          |\n+------------+--------------+------+-----+---------+----------------+\n| id         | int          | NO   | PRI | <span class=\"hljs-keyword\">NULL<\/span>    | auto_increment |\n| first_name | varchar(<span class=\"hljs-number\">50<\/span>)  | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| last_name  | varchar(<span class=\"hljs-number\">50<\/span>)  | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| dob        | date         | NO   |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| phone      | varchar(<span class=\"hljs-number\">20<\/span>)  | YES  |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| email      | varchar(<span class=\"hljs-number\">100<\/span>) | YES  |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n| resume     | longblob     | YES  |     | <span class=\"hljs-keyword\">NULL<\/span>    |                |\n+------------+--------------+------+-----+---------+----------------+\n<span class=\"hljs-number\">7<\/span> rows in set (<span class=\"hljs-number\">0.05<\/span> sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>We&#8217;ll read data from a PDF file and insert it into the <code>resume<\/code> column.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Writing BLOB data to MySQL database<\/h2>\n\n\n\n<p>The following defines <code>addResume()<\/code> method that reads data from a PDF file and inserts it into the <code>resume<\/code> column of the <code>candidates<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Java\" data-shcb-language-slug=\"java\"><span><code class=\"hljs language-java\"><span class=\"hljs-keyword\">import<\/span> java.io.File;\n<span class=\"hljs-keyword\">import<\/span> java.io.FileInputStream;\n<span class=\"hljs-keyword\">import<\/span> java.io.FileNotFoundException;\n<span class=\"hljs-keyword\">import<\/span> java.sql.SQLException;\n<span class=\"hljs-keyword\">import<\/span> java.sql.Date;\n<span class=\"hljs-keyword\">import<\/span> java.sql.Statement;\n<span class=\"hljs-keyword\">import<\/span> java.util.ArrayList;\n\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Candidate<\/span> <\/span>{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">addResume<\/span><span class=\"hljs-params\">(<span class=\"hljs-keyword\">int<\/span> candidateId, String filename)<\/span> <\/span>{\n        <span class=\"hljs-keyword\">var<\/span> sql = <span class=\"hljs-string\">\"UPDATE candidates SET resume = ? WHERE id=?\"<\/span>;\n\n        <span class=\"hljs-keyword\">try<\/span> (<span class=\"hljs-keyword\">var<\/span> conn = MySQLConnection.connect();\n             <span class=\"hljs-keyword\">var<\/span> stmt = conn.prepareStatement(sql)) {\n\n            <span class=\"hljs-comment\">\/\/ read the file<\/span>\n            <span class=\"hljs-keyword\">var<\/span> file = <span class=\"hljs-keyword\">new<\/span> File(filename);\n            <span class=\"hljs-keyword\">var<\/span> input = <span class=\"hljs-keyword\">new<\/span> FileInputStream(file);\n\n            <span class=\"hljs-comment\">\/\/ set parameters<\/span>\n            stmt.setBinaryStream(<span class=\"hljs-number\">1<\/span>, input);\n            stmt.setInt(<span class=\"hljs-number\">2<\/span>, candidateId);\n\n            <span class=\"hljs-comment\">\/\/ store the resume file in database<\/span>\n            stmt.executeUpdate();\n\n        } <span class=\"hljs-keyword\">catch<\/span> (SQLException | FileNotFoundException e) {\n            e.printStackTrace();\n        }\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Java<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">java<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following calls the <code>addResume()<\/code> method to write binary data from <code>C:\\temp\\resume.pdf<\/code> file and insert it into the <code>resume<\/code> column of the <code>candidates<\/code> table for the id 1:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Java\" data-shcb-language-slug=\"java\"><span><code class=\"hljs language-java\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Main<\/span> <\/span>{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">(String&#91;] args)<\/span> <\/span>{\n       Candidate.addResume(<span class=\"hljs-number\">1<\/span>, <span class=\"hljs-string\">\"C:\/temp\/resume.pdf\"<\/span>);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Java<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">java<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you execute the program query the <code>candidates<\/code> table, you&#8217;ll see the BLOB column updated:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> <span class=\"hljs-keyword\">id<\/span>, first_name, <span class=\"hljs-keyword\">LENGTH<\/span>(<span class=\"hljs-keyword\">resume<\/span>)\n<span class=\"hljs-keyword\">FROM<\/span> candidates \n<span class=\"hljs-keyword\">WHERE<\/span> <span class=\"hljs-keyword\">id<\/span> = <span class=\"hljs-number\">1<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">+----+------------+----------------+\n| id | first_name | length(resume) |\n+----+------------+----------------+\n|  1 | Carine     |          23817 |\n+----+------------+----------------+\n1 row in set (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This query retrieves the length of the <code>resume<\/code> column for the row id 1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Reading BLOB data from MySQL database<\/h2>\n\n\n\n<p>The following defines the <code>getResume()<\/code> method that retrieves BLOB data from the <code>resume<\/code> column and writes it to a file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Java\" data-shcb-language-slug=\"java\"><span><code class=\"hljs language-java\"><span class=\"hljs-keyword\">import<\/span> java.io.File;\n<span class=\"hljs-keyword\">import<\/span> java.io.FileInputStream;\n<span class=\"hljs-keyword\">import<\/span> java.io.FileOutputStream;\n<span class=\"hljs-keyword\">import<\/span> java.io.FileNotFoundException;\n<span class=\"hljs-keyword\">import<\/span> java.io.IOException;\n<span class=\"hljs-keyword\">import<\/span> java.sql.SQLException;\n<span class=\"hljs-keyword\">import<\/span> java.sql.Date;\n<span class=\"hljs-keyword\">import<\/span> java.sql.Statement;\n<span class=\"hljs-keyword\">import<\/span> java.util.ArrayList;\n\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Candidate<\/span> <\/span>{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">getResume<\/span><span class=\"hljs-params\">(<span class=\"hljs-keyword\">int<\/span> candidateId, String filename)<\/span><\/span>{\n        <span class=\"hljs-comment\">\/\/ update sql<\/span>\n        <span class=\"hljs-keyword\">var<\/span> sql = <span class=\"hljs-string\">\"SELECT resume FROM candidates WHERE id=?\"<\/span>;\n\n        <span class=\"hljs-keyword\">try<\/span> (<span class=\"hljs-keyword\">var<\/span> conn = MySQLConnection.connect();\n             <span class=\"hljs-keyword\">var<\/span> stmt = conn.prepareStatement(sql)) {\n            <span class=\"hljs-comment\">\/\/ set parameter<\/span>\n            stmt.setInt(<span class=\"hljs-number\">1<\/span>, candidateId);\n            <span class=\"hljs-keyword\">var<\/span> file = <span class=\"hljs-keyword\">new<\/span> File(filename);\n\n            <span class=\"hljs-keyword\">try<\/span>(<span class=\"hljs-keyword\">var<\/span> rs = stmt.executeQuery();\n                <span class=\"hljs-keyword\">var<\/span> output = <span class=\"hljs-keyword\">new<\/span> FileOutputStream(file)){\n                <span class=\"hljs-comment\">\/\/ write binary stream into file<\/span>\n                <span class=\"hljs-keyword\">while<\/span> (rs.next()) {\n                    <span class=\"hljs-keyword\">var<\/span> input = rs.getBinaryStream(<span class=\"hljs-string\">\"resume\"<\/span>);\n                    <span class=\"hljs-keyword\">byte<\/span>&#91;] buffer = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-keyword\">byte<\/span>&#91;<span class=\"hljs-number\">1024<\/span>];\n                    <span class=\"hljs-keyword\">while<\/span> (input.read(buffer) &gt; <span class=\"hljs-number\">0<\/span>) {\n                        output.write(buffer);\n                    }\n                }\n            } <span class=\"hljs-keyword\">catch<\/span> (IOException e){\n                e.printStackTrace();\n            }\n        } <span class=\"hljs-keyword\">catch<\/span> (SQLException  e) {\n            e.printStackTrace();\n        }\n    }\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Java<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">java<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The following shows how to retrieve BLOB data from the resume column of the <code>candidates<\/code> table and write it to a file in the <code>C:\/temp\/resume_blob.pdf<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Java\" data-shcb-language-slug=\"java\"><span><code class=\"hljs language-java\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">Main<\/span> <\/span>{\n    <span class=\"hljs-function\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">(String&#91;] args)<\/span><\/span>{\n        Candidate.getResume(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-string\">\"C:\/temp\/resume_blob.pdf\"<\/span>);\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Java<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">java<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you execute the program, you&#8217;ll see a new file called <code>resume_blob.pdf<\/code> created in the <code>c:\/temp<\/code> directory. <\/p>\n\n\n\n<p>The <code>resume_blob.pdf<\/code> file will be the same as the one that we used to insert into the <code>resume<\/code> column.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3510\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/\"\n\t\t\t\tdata-post-title=\"Writing and Reading MySQL BLOB Using JDBC\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3510\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/\"\n\t\t\t\tdata-post-title=\"Writing and Reading MySQL BLOB Using JDBC\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will show you how to write and read MySQL BLOB data using JDBC API.<\/p>\n","protected":false},"author":2,"featured_media":3680,"parent":3416,"menu_order":8,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3510","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Reading and Writing MySQL BLOB Using JDBC<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to read \/ write BLOB from \/ to MySQL database in JDBC.\" \/>\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.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Reading and Writing MySQL BLOB Using JDBC\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to read \/ write BLOB from \/ to MySQL database in JDBC.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-11T09:27:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-blob.png\" \/>\n\t<meta property=\"og:image:width\" content=\"120\" \/>\n\t<meta property=\"og:image:height\" content=\"100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/\",\"name\":\"Reading and Writing MySQL BLOB Using JDBC\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-blob.png\",\"datePublished\":\"2015-05-17T13:43:55+00:00\",\"dateModified\":\"2024-01-11T09:27:52+00:00\",\"description\":\"In this tutorial, you will learn how to read \\\/ write BLOB from \\\/ to MySQL database in JDBC.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-blob.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-blob.png\",\"width\":120,\"height\":100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/writing-and-reading-mysql-blob-using-jdbc\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL JDBC\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Writing and Reading MySQL BLOB Using JDBC\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Reading and Writing MySQL BLOB Using JDBC","description":"In this tutorial, you will learn how to read \/ write BLOB from \/ to MySQL database in JDBC.","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.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/","og_locale":"en_US","og_type":"article","og_title":"Reading and Writing MySQL BLOB Using JDBC","og_description":"In this tutorial, you will learn how to read \/ write BLOB from \/ to MySQL database in JDBC.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-11T09:27:52+00:00","og_image":[{"width":120,"height":100,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-blob.png","type":"image\/png"}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/","url":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/","name":"Reading and Writing MySQL BLOB Using JDBC","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-blob.png","datePublished":"2015-05-17T13:43:55+00:00","dateModified":"2024-01-11T09:27:52+00:00","description":"In this tutorial, you will learn how to read \/ write BLOB from \/ to MySQL database in JDBC.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-blob.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-blob.png","width":120,"height":100},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/writing-and-reading-mysql-blob-using-jdbc\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL JDBC","item":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/"},{"@type":"ListItem","position":3,"name":"Writing and Reading MySQL BLOB Using JDBC"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=3510"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3510\/revisions"}],"predecessor-version":[{"id":14518,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3510\/revisions\/14518"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/3680"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}