{"id":22873,"date":"2015-04-27T11:00:03","date_gmt":"2015-04-27T08:00:03","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=22873"},"modified":"2019-03-05T13:15:12","modified_gmt":"2019-03-05T11:15:12","slug":"jdbc-batch-insert-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/","title":{"rendered":"JDBC Batch Insert Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated in a <a title=\"JDBC Batch\" href=\"http:\/\/examples.javacodegeeks.com\/core-java\/sql\/jdbc-batch-update-example\/\" target=\"_blank\" rel=\"noopener noreferrer\">previous article<\/a>, the Batch operation exposed in JDBC <i>(Java DataBase Connectivity API)<\/i> helps to bundle together a group of operations and execute them as a single unit. This helps to avoid making repeated database calls for each operation and thereby saves the number of network calls to be made to the database.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<\/p>\n<p>&nbsp;<br \/>\nIt is worth noting that when executing a bunch of operations in a batch one or more operations could fail leading to an unstable state of the database; hence we are going to run the batch operations in transaction units. Think of it as atomic units. This would ensure that if any one of the operations in the batch fails, the whole batch fails. And if all operations in the batch succeed, the whole batch succeeds. To achieve this, the <i>autocommit<\/i> property of the connection object would be turned off and an explicit commit\/rollback of the entire batch would be done as shown in the provided code snippets.<\/p>\n<p>This article will discuss three approaches of batching the \u2018<code>insert<\/code>\u2019 operation. First it will demonstrate using the <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/Statement.html\" target=\"_blank\" rel=\"noopener noreferrer\">Statement<\/a><\/code> Object, then <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/PreparedStatement.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreparedStatement<\/a><\/code> Object and finally, it will show how a large batch of operations could be batched\/chunked in <b>Batching the Batch<\/b> section. The entire example code is available for download at the end of the article.<\/p>\n<h2>2. Project Set-up<\/h2>\n<ul>\n<li>Project Structure\n<ul>\n<li>An Eclipse project would be set up as shown below<\/li>\n<li>Note the use of the external jar: &#8216;<code>mysql-connector-java<\/code>&#8216; for connecting to the database from Eclipse<\/li>\n<\/ul>\n<p><figure id=\"attachment_22950\" aria-describedby=\"caption-attachment-22950\" style=\"width: 456px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/jdbcBatchInsertProjectStructure.png\"><img decoding=\"async\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/jdbcBatchInsertProjectStructure.png\" alt=\"Project structure\" width=\"456\" height=\"361\" class=\"size-full wp-image-22950\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/jdbcBatchInsertProjectStructure.png 456w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/jdbcBatchInsertProjectStructure-300x238.png 300w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/a><figcaption id=\"caption-attachment-22950\" class=\"wp-caption-text\">Project structure<\/figcaption><\/figure><\/li>\n<li>DataBase Connection\n<ul>\n<li>A JDBC Connection will be made to a MySQL database<\/li>\n<li>We will use a <i>persons<\/i> table with the following schema in the database<\/li>\n<\/ul>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>firstName<\/th>\n<th>lastName<\/th>\n<th>age<\/th>\n<th>ID<\/th>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<\/ul>\n<h2>3. Batch Using Statement<\/h2>\n<p>The first approach is using the <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/Statement.html\" target=\"_blank\" rel=\"noopener noreferrer\">Statement<\/a><\/code> object.  It involves the following steps:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul>\n<li>Create a <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/Statement.html\" target=\"_blank\" rel=\"noopener noreferrer\">Statement<\/a><\/code> object.<br \/>\n<i>Notice how the values to be set have to be specified with each insert query. This seems pretty tedious; hence <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/PreparedStatement.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreparedStatement<\/a><\/code> is preferred in most cases which is demonstrated next<\/i>.<\/li>\n<li>Turn autocommit off to run the batch in a single transaction<\/li>\n<li>Add the SQL query to be executed to the Connection object using the <code>addBatch()<\/code> method<\/li>\n<li>Execute the batch<\/li>\n<li>Then do a commit or roll-back<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>ExampleUsingStatement.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">try{\n      Statement stmt = connection.createStatement();\n      connection.autoCommit(false);\n      for(int i=1; i&lt;= 200;i++){\n          stmt.addBatch(\"insert into PERSONS values ('Java','CodeGeeks',\"+i+\",\"+i+\")\");\n      }\n      int[] result = stmt.executeBatch();\n      System.out.println(\"The number of rows inserted: \"+ result.length);\n      connection.commit();\n}catch(Exception e){\n      e.printStackTrace();\n      connection.rollBack();\n} finally{\n      if(stmt!=null)\n      stmt.close();\nif(connection!=null)\n       connection.close();\n}\n<\/pre>\n<h2>4. Batch Using PreparedStatement<\/h2>\n<p>This section uses <code><a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/java\/sql\/PreparedStatement.html\" target=\"_blank\" rel=\"noopener noreferrer\">PreparedStatement<\/a><\/code> object. As can be seen from the code snippets, it allows reusing the basic SQL query. The <code>'?'<\/code> acts as a placeholder for the parameter values which can be supplied later using the <code>addInt(index,value)<\/code> or <code>addString(index,value)<\/code> method as appropriate. Thus, unlike the previous case it is more neat and it also helps to check against SQL Injection threat. The steps are listed as below:[ulp id=&#8217;TD36VgQCKfhTAygK&#8217;]<\/p>\n<ul>\n<li>Create PreparedStatement<\/li>\n<li>Turn off autocommit<\/li>\n<li>Add the parameter values for each query using <code>addInt(index,value)<\/code> or <code>addString(index,value)<\/code><\/li>\n<li>Add to the batch using <code>addBatch()<\/code><\/li>\n<li>Execute the batch<\/li>\n<li>Commit or roll-back the transaction<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>ExampleUsingPreparedStatement.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">String sqlQuery = \"insert into PERSONS values (?,?,?,?)\";\ntry{\n     PreparedStatement pstmt = connection.prepareStatement(sqlQuery);\n     connection.autoCommit(false);\n     for(int i=1; i&lt;= 200;i++){\n          pstmt.setString(1,\"Java\");\n          pstmt.setString(2,\"CodeGeeks\");\n          pstmt.setInt(3,i);\n          pstmt.setInt(4,i);\n          pstmt.addBatch();\n     }\n     int[] result = pstmt.executeBatch();\n     System.out.println(\"The number of rows inserted: \"+ result.length);\n     connection.commit();\n}catch(Exception e){\n     e.printStackTrace();\n     connection.rollBack();\n} finally{\n     if(pstmt!=null)\n        pstmt.close();\nif(connection!=null)\n     connection.close();\n}\n<\/pre>\n<h2>5. Batching the Batch<\/h2>\n<p>In the examples above, we batched around 200 rows together and inserted them into the table. But what if thousands or more records were to be batched and inserted at one go? Well, this could choke the database. The below snippet demonstrates how batch operations could be performed in chunks to avoid such a scenario.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ExampleUsingPreparedStmtBatchSize.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">String sqlQuery = \"insert into PSERSONS values (?,?,?,?)\";\nint count = 0;\nint batchSize = 50;\ntry{\n\t\tconnection.setAutoCommit(false);\n\t\tPreparedStatement pstmt = connection.prepareStatement(SQL);\n\t\t\tfor(int i=1;i&lt;=1000;i++){\n\t\t\t  pstmt.setString(1,\"Java\");\n\t\t\t  pstmt.setString(2,\"CodeGeeks\");\n\t\t\t  pstmt.setInt(3,i);\n\t\t\t  pstmt.setInt(4, i);\n\t\t\t  pstmt.addBatch();\n\t\t\t  \n\t\t\t  count++;\n\t\t\t  \n\t\t\t  if(count % batchSize == 0){\n\t\t\t\t  System.out.println(\"Commit the batch\");\n\t\t\t\t  result = pstmt.executeBatch();\n\t\t\t\t  System.out.println(\"Number of rows inserted: \"+ result.length);\n                                  connection.commit();\n\t\t\t  }\n\t\t\t  \n\t\t}\n               \n}catch(Exception e){\n   e.printStackTrace();\n   connection.rollBack();\n} finally{\n   if(pstmt!=null)\n       pstmt.close();\n   if(connection!=null)\n      connection.close();\n}\n\n<\/pre>\n<h2>6. Download the source code<\/h2>\n<p>Here we come to the end of this article. Hope it was an interesting and helpful read.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nAs promised, the code is available for download here : <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/jdbcBatchInsertExample.zip\">JDBC Batch Insert Example<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated in a previous article, the Batch operation exposed in JDBC (Java DataBase Connectivity API) helps to bundle together a group of operations and execute them as a single &hellip;<\/p>\n","protected":false},"author":49,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-22873","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JDBC Batch Insert Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JDBC Batch Insert Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-27T08:00:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-05T11:15:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-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=\"Joormana Brahma\" \/>\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=\"Joormana Brahma\" \/>\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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\"},\"author\":{\"name\":\"Joormana Brahma\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/dc9d2ec72b84cc70ec2cda0edea4f999\"},\"headline\":\"JDBC Batch Insert Example\",\"datePublished\":\"2015-04-27T08:00:03+00:00\",\"dateModified\":\"2019-03-05T11:15:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\"},\"wordCount\":594,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\",\"name\":\"JDBC Batch Insert Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2015-04-27T08:00:03+00:00\",\"dateModified\":\"2019-03-05T11:15:12+00:00\",\"description\":\"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JDBC Batch Insert Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/dc9d2ec72b84cc70ec2cda0edea4f999\",\"name\":\"Joormana Brahma\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/Joormana-Brahma-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/Joormana-Brahma-96x96.jpg\",\"caption\":\"Joormana Brahma\"},\"description\":\"She has done her graduation in Computer Science and Technology from Guwahati, Assam. She is currently working in a small IT Company as a Software Engineer in Hyderabad, India. She is a member of the Architecture team that is involved in development and quite a bit of R&amp;D. She considers learning and sharing what has been learnt to be a rewarding experience.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/joormana-brahma\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JDBC Batch Insert Example - Java Code Geeks","description":"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated","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:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/","og_locale":"en_US","og_type":"article","og_title":"JDBC Batch Insert Example - Java Code Geeks","og_description":"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-04-27T08:00:03+00:00","article_modified_time":"2019-03-05T11:15:12+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Joormana Brahma","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Joormana Brahma","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/"},"author":{"name":"Joormana Brahma","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/dc9d2ec72b84cc70ec2cda0edea4f999"},"headline":"JDBC Batch Insert Example","datePublished":"2015-04-27T08:00:03+00:00","dateModified":"2019-03-05T11:15:12+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/"},"wordCount":594,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/","name":"JDBC Batch Insert Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2015-04-27T08:00:03+00:00","dateModified":"2019-03-05T11:15:12+00:00","description":"1. Introduction In this article we are going to present a simple example of using JDBC Batch for doing bulk inserts into a relational database. As stated","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/core-java\/sql\/jdbc-batch-insert-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"JDBC Batch Insert Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/dc9d2ec72b84cc70ec2cda0edea4f999","name":"Joormana Brahma","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/Joormana-Brahma-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/04\/Joormana-Brahma-96x96.jpg","caption":"Joormana Brahma"},"description":"She has done her graduation in Computer Science and Technology from Guwahati, Assam. She is currently working in a small IT Company as a Software Engineer in Hyderabad, India. She is a member of the Architecture team that is involved in development and quite a bit of R&amp;D. She considers learning and sharing what has been learnt to be a rewarding experience.","sameAs":["http:\/\/www.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/joormana-brahma\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/49"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=22873"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/22873\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=22873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=22873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=22873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}