{"id":289,"date":"2023-08-02T22:11:27","date_gmt":"2022-09-30T02:18:30","guid":{"rendered":"https:\/\/www.silicloud.com\/ja\/blog\/index.php\/2023\/11\/30\/spring-jdbc%e3%81%ae%e4%be%8b\/"},"modified":"2025-07-31T22:21:51","modified_gmt":"2025-07-31T13:21:51","slug":"spring-jdbc%e3%81%ae%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/","title":{"rendered":"Spring JDBC\u306e\u4f8b"},"content":{"rendered":"<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u30c6\u30fc\u30de\u306fSpring JDBC\u3067\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u307b\u3068\u3093\u3069\u306e\u30a8\u30f3\u30bf\u30fc\u30d7\u30e9\u30a4\u30ba\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u3068\u3063\u3066\u5fc5\u9808\u306e\u8981\u7d20\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001Java EE\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u304a\u3044\u3066JDBC\u3068\u306e\u826f\u597d\u306a\u7d71\u5408\u304c\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002<\/p>\n<h2>Spring JDBC (\u30b9\u30d7\u30ea\u30f3\u30b0 JDBC)<\/h2>\n<p>Spring Framework\u306f\u3001JDBC API\u3068\u512a\u308c\u305f\u7d71\u5408\u3092\u63d0\u4f9b\u3057\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u64cd\u4f5c\u306e\u30ed\u30b8\u30c3\u30af\u304b\u3089\u3001\u63a5\u7d9a\u306e\u30aa\u30fc\u30d7\u30f3\/\u30af\u30ed\u30fc\u30ba\u3001ResultSet\u3001PreparedStatement\u306a\u3069\u306e\u30dc\u30a4\u30e9\u30fc\u30d7\u30ec\u30fc\u30c8\u30b3\u30fc\u30c9\u3092\u907f\u3051\u308b\u305f\u3081\u306b\u4f7f\u7528\u3067\u304d\u308bJdbcTemplate\u30e6\u30fc\u30c6\u30a3\u30ea\u30c6\u30a3\u30af\u30e9\u30b9\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u307e\u305a\u306f\u3001\u30b7\u30f3\u30d7\u30eb\u306aSpring JDBC\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u305d\u306e\u5f8c\u3001\u3069\u306e\u3088\u3046\u306bJdbcTemplate\u30af\u30e9\u30b9\u304c\u30e2\u30b8\u30e5\u30e9\u30fc\u306a\u30b3\u30fc\u30c9\u306e\u4f5c\u6210\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u3066\u304f\u308c\u308b\u304b\u3092\u898b\u3066\u3044\u304d\u307e\u3059\u3002\u30ea\u30bd\u30fc\u30b9\u304c\u9069\u5207\u306b\u30af\u30ed\u30fc\u30ba\u3055\u308c\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u3092\u5fc3\u914d\u3059\u308b\u3053\u3068\u306a\u304f\u3001\u7c21\u5358\u306b\u66f8\u304f\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Spring\u30d9\u30fc\u30b9\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u958b\u767a\u3059\u308b\u305f\u3081\u306eSpring Tool Suite\u306f\u975e\u5e38\u306b\u4fbf\u5229\u3067\u3059\u306e\u3067\u3001\u79c1\u305f\u3061\u306fSTS\u3092\u4f7f\u7528\u3057\u3066Spring JDBC\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u6700\u7d42\u7684\u306a\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306e\u69cb\u9020\u306f\u4ee5\u4e0b\u306e\u753b\u50cf\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002STS\u30e1\u30cb\u30e5\u30fc\u304b\u3089\u30b7\u30f3\u30d7\u30eb\u306aSpring Maven\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3001\u304a\u597d\u304d\u306a\u540d\u524d\u3092\u9078\u629e\u3059\u308b\u304b\u3001\u79c1\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d\u300cSpringJDBCExample\u300d\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u30b9\u30d7\u30ea\u30f3\u30b0\u306eJDBC\u4f9d\u5b58\u95a2\u4fc2<\/h3>\n<p>\u307e\u305a\u3001Maven\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u306epom.xml\u30d5\u30a1\u30a4\u30eb\u306bSpring JDBC\u3068\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c9\u30e9\u30a4\u30d0\u3092\u8ffd\u52a0\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u79c1\u306e\u6700\u7d42\u7684\u306apom.xml\u30d5\u30a1\u30a4\u30eb\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;project xmlns=\"https:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"https:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t&lt;groupId&gt;org.springframework.samples&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;SpringJDBCExample&lt;\/artifactId&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\r\n\t&lt;properties&gt;\r\n\r\n\t\t&lt;!-- Generic properties --&gt;\r\n\t\t&lt;java.version&gt;1.6&lt;\/java.version&gt;\r\n\t\t&lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n\t\t&lt;project.reporting.outputEncoding&gt;UTF-8&lt;\/project.reporting.outputEncoding&gt;\r\n\r\n\t\t&lt;!-- Spring --&gt;\r\n\t\t&lt;spring-framework.version&gt;4.0.2.RELEASE&lt;\/spring-framework.version&gt;\r\n\r\n\t\t&lt;!-- Logging --&gt;\r\n\t\t&lt;logback.version&gt;1.0.13&lt;\/logback.version&gt;\r\n\t\t&lt;slf4j.version&gt;1.7.5&lt;\/slf4j.version&gt;\r\n\r\n\t&lt;\/properties&gt;\r\n\r\n\t&lt;dependencies&gt;\r\n\t\t&lt;!-- Spring and Transactions --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-context&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring-framework.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-tx&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring-framework.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t\t&lt;!-- Spring JDBC Support --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.springframework&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;spring-jdbc&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${spring-framework.version}&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t\r\n\t\t&lt;!-- MySQL Driver --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;mysql&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;mysql-connector-java&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;5.0.5&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t\t&lt;!-- Logging with SLF4J &amp; LogBack --&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.slf4j&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;slf4j-api&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${slf4j.version}&lt;\/version&gt;\r\n\t\t\t&lt;scope&gt;compile&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;ch.qos.logback&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;logback-classic&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;${logback.version}&lt;\/version&gt;\r\n\t\t\t&lt;scope&gt;runtime&lt;\/scope&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n\t&lt;\/dependencies&gt;\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<p>\u307b\u3068\u3093\u3069\u306e\u90e8\u5206\u306fSTS\u306b\u3088\u3063\u3066\u81ea\u52d5\u7684\u306b\u751f\u6210\u3055\u308c\u307e\u3059\u304c\u3001Spring Framework\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u6700\u65b0\u306e4.0.2.RELEASE\u306b\u66f4\u65b0\u3057\u307e\u3057\u305f\u3002\u307e\u305f\u3001\u5fc5\u8981\u306a\u30a2\u30fc\u30c6\u30a3\u30d5\u30a1\u30af\u30c8\u3067\u3042\u308bspring-jdbc\u3068mysql-connector-java\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u6700\u521d\u306e\u3082\u306e\u306fSpring JDBC\u306e\u30b5\u30dd\u30fc\u30c8\u30af\u30e9\u30b9\u3092\u542b\u307f\u30012\u756a\u76ee\u306e\u3082\u306e\u306f\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30c9\u30e9\u30a4\u30d0\u30fc\u3067\u3059\u3002\u79c1\u305f\u3061\u306f\u30c6\u30b9\u30c8\u306e\u76ee\u7684\u3067MySQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u305f\u3081\u3001MySQL JConnector\u306ejar\u4f9d\u5b58\u95a2\u4fc2\u3092\u8ffd\u52a0\u3057\u307e\u3057\u305f\u3002\u4ed6\u306eRDBMS\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u306f\u3001\u4f9d\u5b58\u95a2\u4fc2\u3092\u5bfe\u5fdc\u3059\u308b\u5909\u66f4\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>Spring JDBC\u306e\u4f8b &#8211; \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h3>\n<p>\u79c1\u305f\u3061\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3067\u4f7f\u7528\u3059\u308b\u30b7\u30f3\u30d7\u30eb\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002CRUD\u64cd\u4f5c\u306e\u4f8b\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>CREATE TABLE `Employee` (\r\n  `id` int(11) unsigned NOT NULL,\r\n  `name` varchar(20) DEFAULT NULL,\r\n  `role` varchar(20) DEFAULT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n<\/code><\/pre>\n<h3>Spring JDBC\u306e\u4f8b &#8211; \u30e2\u30c7\u30eb\u30af\u30e9\u30b9<\/h3>\n<p>JDBC\u64cd\u4f5c\u306b\u306fDAO\u30d1\u30bf\u30fc\u30f3\u3092\u4f7f\u7528\u3057\u307e\u3059\u306e\u3067\u3001Java\u306e\u30d3\u30fc\u30f3\u3092\u4f5c\u6210\u3057\u307e\u3057\u3087\u3046\u3002\u3053\u306e\u30d3\u30fc\u30f3\u306f\u3001Employee\u30c6\u30fc\u30d6\u30eb\u3092\u30e2\u30c7\u30eb\u5316\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.jdbc.model;\r\n\r\npublic class Employee {\r\n\r\n\tprivate int id;\r\n\tprivate String name;\r\n\tprivate String role;\r\n\t\r\n\tpublic int getId() {\r\n\t\treturn id;\r\n\t}\r\n\tpublic void setId(int id) {\r\n\t\tthis.id = id;\r\n\t}\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\tpublic String getRole() {\r\n\t\treturn role;\r\n\t}\r\n\tpublic void setRole(String role) {\r\n\t\tthis.role = role;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic String toString(){\r\n\t\treturn \"{ID=\"+id+\",Name=\"+name+\",Role=\"+role+\"}\";\r\n\t}\r\n}\r\n<\/code><\/pre>\n<h3>\u30b9\u30d7\u30ea\u30f3\u30b0JDBC\u306e\u4f8b &#8211; DAO\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3068\u5b9f\u88c5<\/h3>\n<p>DAO\u30d1\u30bf\u30fc\u30f3\u3067\u306f\u3001\u6700\u521d\u306b\u5b9f\u88c5\u3057\u305f\u3044\u3059\u3079\u3066\u306e\u64cd\u4f5c\u3092\u5ba3\u8a00\u3059\u308b\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.jdbc.dao;\r\n\r\nimport java.util.List;\r\n\r\nimport com.scdev.spring.jdbc.model.Employee;\r\n\r\n\/\/CRUD operations\r\npublic interface EmployeeDAO {\r\n\t\r\n\t\/\/Create\r\n\tpublic void save(Employee employee);\r\n\t\/\/Read\r\n\tpublic Employee getById(int id);\r\n\t\/\/Update\r\n\tpublic void update(Employee employee);\r\n\t\/\/Delete\r\n\tpublic void deleteById(int id);\r\n\t\/\/Get All\r\n\tpublic List&lt;Employee&gt; getAll();\r\n}\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>package com.scdev.spring.jdbc.dao;\r\n\r\nimport java.sql.Connection;\r\nimport java.sql.PreparedStatement;\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\n\r\nimport javax.sql.DataSource;\r\n\r\nimport com.scdev.spring.jdbc.model.Employee;\r\n\r\npublic class EmployeeDAOImpl implements EmployeeDAO {\r\n\r\n\tprivate DataSource dataSource;\r\n\r\n\tpublic void setDataSource(DataSource dataSource) {\r\n\t\tthis.dataSource = dataSource;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void save(Employee employee) {\r\n\t\tString query = \"insert into Employee (id, name, role) values (?,?,?)\";\r\n\t\tConnection con = null;\r\n\t\tPreparedStatement ps = null;\r\n\t\ttry{\r\n\t\t\tcon = dataSource.getConnection();\r\n\t\t\tps = con.prepareStatement(query);\r\n\t\t\tps.setInt(1, employee.getId());\r\n\t\t\tps.setString(2, employee.getName());\r\n\t\t\tps.setString(3, employee.getRole());\r\n\t\t\tint out = ps.executeUpdate();\r\n\t\t\tif(out !=0){\r\n\t\t\t\tSystem.out.println(\"Employee saved with id=\"+employee.getId());\r\n\t\t\t}else System.out.println(\"Employee save failed with id=\"+employee.getId());\r\n\t\t}catch(SQLException e){\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\ttry {\r\n\t\t\t\tps.close();\r\n\t\t\t\tcon.close();\r\n\t\t\t} catch (SQLException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Employee getById(int id) {\r\n\t\tString query = \"select name, role from Employee where id = ?\";\r\n\t\tEmployee emp = null;\r\n\t\tConnection con = null;\r\n\t\tPreparedStatement ps = null;\r\n\t\tResultSet rs = null;\r\n\t\ttry{\r\n\t\t\tcon = dataSource.getConnection();\r\n\t\t\tps = con.prepareStatement(query);\r\n\t\t\tps.setInt(1, id);\r\n\t\t\trs = ps.executeQuery();\r\n\t\t\tif(rs.next()){\r\n\t\t\t\temp = new Employee();\r\n\t\t\t\temp.setId(id);\r\n\t\t\t\temp.setName(rs.getString(\"name\"));\r\n\t\t\t\temp.setRole(rs.getString(\"role\"));\r\n\t\t\t\tSystem.out.println(\"Employee Found::\"+emp);\r\n\t\t\t}else{\r\n\t\t\t\tSystem.out.println(\"No Employee found with id=\"+id);\r\n\t\t\t}\r\n\t\t}catch(SQLException e){\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\ttry {\r\n\t\t\t\trs.close();\r\n\t\t\t\tps.close();\r\n\t\t\t\tcon.close();\r\n\t\t\t} catch (SQLException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn emp;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void update(Employee employee) {\r\n\t\tString query = \"update Employee set name=?, role=? where id=?\";\r\n\t\tConnection con = null;\r\n\t\tPreparedStatement ps = null;\r\n\t\ttry{\r\n\t\t\tcon = dataSource.getConnection();\r\n\t\t\tps = con.prepareStatement(query);\r\n\t\t\tps.setString(1, employee.getName());\r\n\t\t\tps.setString(2, employee.getRole());\r\n\t\t\tps.setInt(3, employee.getId());\r\n\t\t\tint out = ps.executeUpdate();\r\n\t\t\tif(out !=0){\r\n\t\t\t\tSystem.out.println(\"Employee updated with id=\"+employee.getId());\r\n\t\t\t}else System.out.println(\"No Employee found with id=\"+employee.getId());\r\n\t\t}catch(SQLException e){\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\ttry {\r\n\t\t\t\tps.close();\r\n\t\t\t\tcon.close();\r\n\t\t\t} catch (SQLException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void deleteById(int id) {\r\n\t\tString query = \"delete from Employee where id=?\";\r\n\t\tConnection con = null;\r\n\t\tPreparedStatement ps = null;\r\n\t\ttry{\r\n\t\t\tcon = dataSource.getConnection();\r\n\t\t\tps = con.prepareStatement(query);\r\n\t\t\tps.setInt(1, id);\r\n\t\t\tint out = ps.executeUpdate();\r\n\t\t\tif(out !=0){\r\n\t\t\t\tSystem.out.println(\"Employee deleted with id=\"+id);\r\n\t\t\t}else System.out.println(\"No Employee found with id=\"+id);\r\n\t\t}catch(SQLException e){\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\ttry {\r\n\t\t\t\tps.close();\r\n\t\t\t\tcon.close();\r\n\t\t\t} catch (SQLException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t@Override\r\n\tpublic List&lt;Employee&gt; getAll() {\r\n\t\tString query = \"select id, name, role from Employee\";\r\n\t\tList&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();\r\n\t\tConnection con = null;\r\n\t\tPreparedStatement ps = null;\r\n\t\tResultSet rs = null;\r\n\t\ttry{\r\n\t\t\tcon = dataSource.getConnection();\r\n\t\t\tps = con.prepareStatement(query);\r\n\t\t\trs = ps.executeQuery();\r\n\t\t\twhile(rs.next()){\r\n\t\t\t\tEmployee emp = new Employee();\r\n\t\t\t\temp.setId(rs.getInt(\"id\"));\r\n\t\t\t\temp.setName(rs.getString(\"name\"));\r\n\t\t\t\temp.setRole(rs.getString(\"role\"));\r\n\t\t\t\tempList.add(emp);\r\n\t\t\t}\r\n\t\t}catch(SQLException e){\r\n\t\t\te.printStackTrace();\r\n\t\t}finally{\r\n\t\t\ttry {\r\n\t\t\t\trs.close();\r\n\t\t\t\tps.close();\r\n\t\t\t\tcon.close();\r\n\t\t\t} catch (SQLException e) {\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn empList;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>CRUD\u64cd\u4f5c\u306e\u5b9f\u88c5\u306f\u7406\u89e3\u3057\u3084\u3059\u3044\u3067\u3059\u3002DataSource\u306b\u3064\u3044\u3066\u3055\u3089\u306b\u5b66\u3073\u305f\u3044\u5834\u5408\u306f\u3001JDBC DataSource\u306e\u4f8b\u3092\u8aad\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u6625\u306eJDBC\u306e\u4f8b &#8211; \u30d3\u30fc\u30f3\u306e\u8a2d\u5b9a<\/h3>\n<p>\u3082\u3057\u4e0a\u8a18\u306e\u3059\u3079\u3066\u306e\u30af\u30e9\u30b9\u3092\u898b\u308b\u3068\u3001\u3059\u3079\u3066\u306e\u30af\u30e9\u30b9\u306f\u6a19\u6e96\u306eJDBC API\u3092\u4f7f\u7528\u3057\u3066\u304a\u308a\u3001Spring JDBC\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3078\u306e\u53c2\u7167\u306f\u3042\u308a\u307e\u305b\u3093\u3002Spring JDBC\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u30af\u30e9\u30b9\u306f\u3001Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30d3\u30fc\u30f3\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u306b\u753b\u9762\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u3002Spring Bean\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3067DataSource\u3092\u4f5c\u6210\u3057\u3001DAO\u5b9f\u88c5\u30af\u30e9\u30b9\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306b\u79c1\u306eSpring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u4f8b\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;beans xmlns=\"https:\/\/www.springframework.org\/schema\/beans\"\r\n\txmlns:xsi=\"https:\/\/www.w3.org\/2001\/XMLSchema-instance\"\r\n\txsi:schemaLocation=\"https:\/\/www.springframework.org\/schema\/beans https:\/\/www.springframework.org\/schema\/beans\/spring-beans.xsd\"&gt;\r\n\r\n\t&lt;bean id=\"employeeDAO\" class=\"com.scdev.spring.jdbc.dao.EmployeeDAOImpl\"&gt;\r\n\t\t&lt;property name=\"dataSource\" ref=\"dataSource\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\t\r\n\t&lt;bean id=\"dataSource\" class=\"org.springframework.jdbc.datasource.DriverManagerDataSource\"&gt;\r\n\r\n\t\t&lt;property name=\"driverClassName\" value=\"com.mysql.jdbc.Driver\" \/&gt;\r\n\t\t&lt;property name=\"url\" value=\"jdbc:mysql:\/\/localhost:3306\/TestDB\" \/&gt;\r\n\t\t&lt;property name=\"username\" value=\"scdev\" \/&gt;\r\n\t\t&lt;property name=\"password\" value=\"scdev123\" \/&gt;\r\n\t&lt;\/bean&gt;\r\n\r\n&lt;\/beans&gt;\r\n<\/code><\/pre>\n<p>\u307e\u305a\u3001\u30af\u30e9\u30b9DriverManagerDataSource\u306eDataSource\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30af\u30e9\u30b9\u306f\u3001\u4f7f\u7528\u3067\u304d\u308bDataSource\u306e\u57fa\u672c\u7684\u306a\u5b9f\u88c5\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002MySQL\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306eURL\u3001\u30e6\u30fc\u30b6\u30fc\u540d\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u3057\u3066DataSource\u30d3\u30fc\u30f3\u306b\u6e21\u3057\u3066\u3044\u307e\u3059\u3002\u307e\u305f\u3001dataSource\u30d3\u30fc\u30f3\u3092EmployeeDAOImpl\u30d3\u30fc\u30f3\u306b\u30bb\u30c3\u30c8\u3057\u3001Spring JDBC\u306e\u5b9f\u88c5\u3092\u6e96\u5099\u3057\u307e\u3059\u3002\u3053\u306e\u5b9f\u88c5\u306f\u758e\u7d50\u5408\u3067\u3042\u308a\u3001\u4ed6\u306e\u5b9f\u88c5\u306b\u5207\u308a\u66ff\u3048\u305f\u308a\u3001\u5225\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u30b5\u30fc\u30d0\u30fc\u306b\u79fb\u884c\u3059\u308b\u5834\u5408\u306f\u3001\u30d3\u30fc\u30f3\u306e\u8a2d\u5b9a\u3092\u5bfe\u5fdc\u3059\u308b\u3088\u3046\u306b\u5909\u66f4\u3059\u308b\u3060\u3051\u3067\u6e08\u307f\u307e\u3059\u3002\u3053\u308c\u306f\u3001Spring JDBC\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u304c\u63d0\u4f9b\u3059\u308b\u4e3b\u8981\u306a\u5229\u70b9\u306e\u4e00\u3064\u3067\u3059\u3002<\/p>\n<h3>Spring JDBC\u306e\u30c6\u30b9\u30c8\u30af\u30e9\u30b9<\/h3>\n<p>\u3059\u3079\u3066\u304c\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3066\u3044\u308b\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u305f\u3081\u306b\u3001\u7c21\u5358\u306a\u30c6\u30b9\u30c8\u30af\u30e9\u30b9\u3092\u66f8\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.jdbc.main;\r\n\r\nimport java.util.List;\r\nimport java.util.Random;\r\n\r\nimport org.springframework.context.support.ClassPathXmlApplicationContext;\r\n\r\nimport com.scdev.spring.jdbc.dao.EmployeeDAO;\r\nimport com.scdev.spring.jdbc.model.Employee;\r\n\r\npublic class SpringMain {\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\t\/\/Get the Spring Context\r\n\t\tClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(\"spring.xml\");\r\n\t\t\r\n\t\t\/\/Get the EmployeeDAO Bean\r\n\t\tEmployeeDAO employeeDAO = ctx.getBean(\"employeeDAO\", EmployeeDAO.class);\r\n\t\t\r\n\t\t\/\/Run some tests for JDBC CRUD operations\r\n\t\tEmployee emp = new Employee();\r\n\t\tint rand = new Random().nextInt(1000);\r\n\t\temp.setId(rand);\r\n\t\temp.setName(\"Pankaj\");\r\n\t\temp.setRole(\"Java Developer\");\r\n\t\t\r\n\t\t\/\/Create\r\n\t\temployeeDAO.save(emp);\r\n\t\t\r\n\t\t\/\/Read\r\n\t\tEmployee emp1 = employeeDAO.getById(rand);\r\n\t\tSystem.out.println(\"Employee Retrieved::\"+emp1);\r\n\t\t\r\n\t\t\/\/Update\r\n\t\temp.setRole(\"CEO\");\r\n\t\temployeeDAO.update(emp);\r\n\t\t\r\n\t\t\/\/Get All\r\n\t\tList&lt;Employee&gt; empList = employeeDAO.getAll();\r\n\t\tSystem.out.println(empList);\r\n\t\t\r\n\t\t\/\/Delete\r\n\t\temployeeDAO.deleteById(rand);\r\n\t\t\r\n\t\t\/\/Close Spring Context\r\n\t\tctx.close();\r\n\t\t\r\n\t\tSystem.out.println(\"DONE\");\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>\u5f93\u696d\u54e1ID\u306e\u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5024\u3092\u751f\u6210\u3059\u308b\u305f\u3081\u306b\u3001\u30e9\u30f3\u30c0\u30e0\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002\u4e0a\u8a18\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u51fa\u529b\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>Mar 25, 2014 12:54:18 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh\r\nINFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4b9af9a9: startup date [Tue Mar 25 12:54:18 PDT 2014]; root of context hierarchy\r\nMar 25, 2014 12:54:18 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions\r\nINFO: Loading XML bean definitions from class path resource [spring.xml]\r\nMar 25, 2014 12:54:19 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName\r\nINFO: Loaded JDBC driver: com.mysql.jdbc.Driver\r\nEmployee saved with id=726\r\nEmployee Found::{ID=726,Name=Pankaj,Role=Java Developer}\r\nEmployee Retrieved::{ID=726,Name=Pankaj,Role=Java Developer}\r\nEmployee updated with id=726\r\n[{ID=726,Name=Pankaj,Role=CEO}]\r\nEmployee deleted with id=726\r\nMar 25, 2014 12:54:19 PM org.springframework.context.support.ClassPathXmlApplicationContext doClose\r\nINFO: Closing org.springframework.context.support.ClassPathXmlApplicationContext@4b9af9a9: startup date [Tue Mar 25 12:54:18 PDT 2014]; root of context hierarchy\r\nDONE\r\n<\/code><\/pre>\n<h2>\u30b9\u30d7\u30ea\u30f3\u30b0\u306eJdbcTemplate\u306e\u4f8b<\/h2>\n<p>DAO\u306e\u5b9f\u88c5\u30af\u30e9\u30b9\u3092\u898b\u308b\u3068\u3001Connection\u3001PreparedStatements\u3001ResultSet\u3092\u958b\u3044\u305f\u308a\u9589\u3058\u305f\u308a\u3059\u308b\u305f\u3081\u306e\u591a\u304f\u306e\u96db\u5f62\u30b3\u30fc\u30c9\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30ea\u30bd\u30fc\u30b9\u3092\u6b63\u3057\u304f\u9589\u3058\u5fd8\u308c\u308b\u3068\u30ea\u30bd\u30fc\u30b9\u30ea\u30fc\u30af\u306b\u3064\u306a\u304c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u3089\u306e\u30a8\u30e9\u30fc\u3092\u56de\u907f\u3059\u308b\u305f\u3081\u306b\u3001org.springframework.jdbc.core.JdbcTemplate\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002Spring JdbcTemplate\u306f\u3001Spring JDBC\u30b3\u30a2\u30d1\u30c3\u30b1\u30fc\u30b8\u306e\u4e2d\u5fc3\u7684\u306a\u30af\u30e9\u30b9\u3067\u3001\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3057\u3001\u81ea\u52d5\u7684\u306bResultSet\u3092\u30d1\u30fc\u30b9\u3057\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u307e\u305f\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ea\u30b9\u30c8\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u591a\u304f\u306e\u30e1\u30bd\u30c3\u30c9\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002\u5fc5\u8981\u306a\u306e\u306f\u3001\u5f15\u6570\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u914d\u5217\u3068\u3057\u3066\u63d0\u4f9b\u3057\u3001PreparedStatementSetter\u3084RowMapper\u306e\u3088\u3046\u306a\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30fc\u30b9\u3092\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u7570\u306a\u308b\u30bf\u30a4\u30d7\u306e\u30af\u30a8\u30ea\u3092\u5b9f\u884c\u3059\u308b\u305f\u3081\u306bSpring JdbcTemplate\u30af\u30e9\u30b9\u3092\u4f7f\u7528\u3059\u308bEmployeeDAO\u306e\u5225\u306e\u5b9f\u88c5\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"post-pre\"><code>package com.scdev.spring.jdbc.dao;\r\n\r\nimport java.sql.ResultSet;\r\nimport java.sql.SQLException;\r\nimport java.util.ArrayList;\r\nimport java.util.List;\r\nimport java.util.Map;\r\n\r\nimport javax.sql.DataSource;\r\n\r\nimport org.springframework.jdbc.core.JdbcTemplate;\r\nimport org.springframework.jdbc.core.RowMapper;\r\n\r\nimport com.scdev.spring.jdbc.model.Employee;\r\n\r\npublic class EmployeeDAOJDBCTemplateImpl implements EmployeeDAO {\r\n\r\n\tprivate DataSource dataSource;\r\n\r\n\tpublic void setDataSource(DataSource dataSource) {\r\n\t\tthis.dataSource = dataSource;\r\n\t}\r\n\t\r\n\t@Override\r\n\tpublic void save(Employee employee) {\r\n\t\tString query = \"insert into Employee (id, name, role) values (?,?,?)\";\r\n\t\t\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);\r\n\t\t\r\n\t\tObject[] args = new Object[] {employee.getId(), employee.getName(), employee.getRole()};\r\n\t\t\r\n\t\tint out = jdbcTemplate.update(query, args);\r\n\t\t\r\n\t\tif(out !=0){\r\n\t\t\tSystem.out.println(\"Employee saved with id=\"+employee.getId());\r\n\t\t}else System.out.println(\"Employee save failed with id=\"+employee.getId());\r\n\t}\r\n\r\n\t@Override\r\n\tpublic Employee getById(int id) {\r\n\t\tString query = \"select id, name, role from Employee where id = ?\";\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);\r\n\t\t\r\n\t\t\/\/using RowMapper anonymous class, we can create a separate RowMapper for reuse\r\n\t\tEmployee emp = jdbcTemplate.queryForObject(query, new Object[]{id}, new RowMapper&lt;Employee&gt;(){\r\n\r\n\t\t\t@Override\r\n\t\t\tpublic Employee mapRow(ResultSet rs, int rowNum)\r\n\t\t\t\t\tthrows SQLException {\r\n\t\t\t\tEmployee emp = new Employee();\r\n\t\t\t\temp.setId(rs.getInt(\"id\"));\r\n\t\t\t\temp.setName(rs.getString(\"name\"));\r\n\t\t\t\temp.setRole(rs.getString(\"role\"));\r\n\t\t\t\treturn emp;\r\n\t\t\t}});\r\n\t\t\r\n\t\treturn emp;\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void update(Employee employee) {\r\n\t\tString query = \"update Employee set name=?, role=? where id=?\";\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);\r\n\t\tObject[] args = new Object[] {employee.getName(), employee.getRole(), employee.getId()};\r\n\t\t\r\n\t\tint out = jdbcTemplate.update(query, args);\r\n\t\tif(out !=0){\r\n\t\t\tSystem.out.println(\"Employee updated with id=\"+employee.getId());\r\n\t\t}else System.out.println(\"No Employee found with id=\"+employee.getId());\r\n\t}\r\n\r\n\t@Override\r\n\tpublic void deleteById(int id) {\r\n\r\n\t\tString query = \"delete from Employee where id=?\";\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);\r\n\t\t\r\n\t\tint out = jdbcTemplate.update(query, id);\r\n\t\tif(out !=0){\r\n\t\t\tSystem.out.println(\"Employee deleted with id=\"+id);\r\n\t\t}else System.out.println(\"No Employee found with id=\"+id);\r\n\t}\r\n\r\n\t@Override\r\n\tpublic List&lt;Employee&gt; getAll() {\r\n\t\tString query = \"select id, name, role from Employee\";\r\n\t\tJdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);\r\n\t\tList&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();\r\n\r\n\t\tList&lt;Map&lt;String,Object&gt;&gt; empRows = jdbcTemplate.queryForList(query);\r\n\t\t\r\n\t\tfor(Map&lt;String,Object&gt; empRow : empRows){\r\n\t\t\tEmployee emp = new Employee();\r\n\t\t\temp.setId(Integer.parseInt(String.valueOf(empRow.get(\"id\"))));\r\n\t\t\temp.setName(String.valueOf(empRow.get(\"name\")));\r\n\t\t\temp.setRole(String.valueOf(empRow.get(\"role\")));\r\n\t\t\tempList.add(emp);\r\n\t\t}\r\n\t\treturn empList;\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n<p>Spring JdbcTemplate\u306e\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u306b\u6ce8\u76ee\u3059\u3079\u304d\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\uff1a<\/p>\n<ul class=\"post-ul\">\n<li>Use of Object array to pass PreparedStatement arguments, we could also use PreparedStatementSetter implementation but passing Object array seems easy to use.<\/li>\n<li>No code related to opening and closing connections, statements or result set. All that is handled internally by Spring JdbcTemplate class.<\/li>\n<li>RowMapper anonymous class implementation to map the ResultSet data to Employee bean object in queryForObject() method.<\/li>\n<li>queryForList() method returns list of Map whereas Map contains the row data mapped with key as the column name and value from the database row matching the criteria.<\/li>\n<\/ul>\n<p>Spring\u306eJdbcTemplate\u5b9f\u88c5\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u306b\u306f\u3001\u4ee5\u4e0b\u306b\u793a\u3059\u901a\u308a\u3001Spring Bean\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u5185\u306eemployeeDAO\u30af\u30e9\u30b9\u3092\u5909\u66f4\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre class=\"post-pre\"><code>&lt;bean id=\"employeeDAO\" class=\"com.scdev.spring.jdbc.dao.EmployeeDAOJDBCTemplateImpl\"&gt;\r\n\t&lt;property name=\"dataSource\" ref=\"dataSource\" \/&gt;\r\n&lt;\/bean&gt;\r\n<\/code><\/pre>\n<p>\u30e1\u30a4\u30f3\u30af\u30e9\u30b9\u3092\u5b9f\u884c\u3059\u308b\u3068\u3001Spring JdbcTemplate\u306e\u5b9f\u88c5\u306b\u3088\u308b\u51fa\u529b\u306f\u901a\u5e38\u306eJDBC\u5b9f\u88c5\u3067\u898b\u305f\u3082\u306e\u3068\u985e\u4f3c\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u304cSpring JDBC\u306e\u4f8b\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u5168\u3066\u3067\u3059\u3002\u4ee5\u4e0b\u306e\u30ea\u30f3\u30af\u304b\u3089\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3001\u3055\u3089\u306b\u5b66\u3076\u305f\u3081\u306b\u8a66\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>Spring JDBC \u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306e\u30c6\u30fc\u30de\u306fSpring JDBC\u3067\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306f\u307b\u3068\u3093\u3069\u306e\u30a8\u30f3\u30bf\u30fc\u30d7\u30e9\u30a4\u30ba\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306b\u3068\u3063\u3066\u5fc5\u9808\u306e\u8981\u7d20\u3067\u3059\u3002\u305d\u306e\u305f\u3081\u3001Java EE\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306b\u304a\u3044\u3066JDBC\u3068\u306e\u826f\u597d\u306a\u7d71\u5408\u304c\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059 [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[26,61],"class_list":["post-289","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-26","tag-61"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring JDBC\u306e\u4f8b - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\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.silicloud.com\/ja\/blog\/spring-jdbc\u306e\u4f8b\/\" \/>\n<meta property=\"og:locale\" content=\"ja_JP\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring JDBC\u306e\u4f8b\" \/>\n<meta property=\"og:description\" content=\"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc\u306e\u4f8b\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-30T02:18:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T13:21:51+00:00\" \/>\n<meta name=\"author\" content=\"\u5149, \u660e\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u57f7\u7b46\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5149, \u660e\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593\" \/>\n\t<meta name=\"twitter:data2\" content=\"39\u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/\",\"name\":\"Spring JDBC\u306e\u4f8b - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\"},\"datePublished\":\"2022-09-30T02:18:30+00:00\",\"dateModified\":\"2025-07-31T13:21:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55\"},\"description\":\"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#breadcrumb\"},\"inLanguage\":\"ja\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/ja\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring JDBC\u306e\u4f8b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"ja\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55\",\"name\":\"\u5149, \u660e\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g\",\"caption\":\"\u5149, \u660e\"},\"url\":\"https:\/\/www.silicloud.com\/ja\/blog\/author\/hikariakira\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"ja\",\"@id\":\"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring JDBC\u306e\u4f8b - Blog - Silicon Cloud","description":"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","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.silicloud.com\/ja\/blog\/spring-jdbc\u306e\u4f8b\/","og_locale":"ja_JP","og_type":"article","og_title":"Spring JDBC\u306e\u4f8b","og_description":"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","og_url":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc\u306e\u4f8b\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2022-09-30T02:18:30+00:00","article_modified_time":"2025-07-31T13:21:51+00:00","author":"\u5149, \u660e","twitter_card":"summary_large_image","twitter_misc":{"\u57f7\u7b46\u8005":"\u5149, \u660e","\u63a8\u5b9a\u8aad\u307f\u53d6\u308a\u6642\u9593":"39\u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/","url":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/","name":"Spring JDBC\u306e\u4f8b - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website"},"datePublished":"2022-09-30T02:18:30+00:00","dateModified":"2025-07-31T13:21:51+00:00","author":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55"},"description":"Spring JDBC\u306e\u4f8b\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac\u3002\u5b9f\u8df5\u7684\u306a\u4f8b\u3068\u30b3\u30fc\u30c9\u3001\u6ce8\u610f\u70b9\u3092\u542b\u3081\u3066\u521d\u5fc3\u8005\u306b\u3082\u7406\u89e3\u3067\u304d\u308b\u3088\u3046\u8aac\u660e\u3057\u307e\u3059\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#breadcrumb"},"inLanguage":"ja","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/ja\/blog\/"},{"@type":"ListItem","position":2,"name":"Spring JDBC\u306e\u4f8b"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#website","url":"https:\/\/www.silicloud.com\/ja\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"ja"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/9ee62cea876d247deba14a0ac7ba5b55","name":"\u5149, \u660e","image":{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3dffb6c754b95e3fbdcd8973f4375ff9dd10d41e4f6632ad08d4d59ccc35af8d?s=96&d=mm&r=g","caption":"\u5149, \u660e"},"url":"https:\/\/www.silicloud.com\/ja\/blog\/author\/hikariakira\/"},{"@type":"ImageObject","inLanguage":"ja","@id":"https:\/\/www.silicloud.com\/ja\/blog\/spring-jdbc%e3%81%ae%e4%be%8b\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/comments?post=289"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions"}],"predecessor-version":[{"id":38710,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/posts\/289\/revisions\/38710"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/media?parent=289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/categories?post=289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/ja\/blog\/wp-json\/wp\/v2\/tags?post=289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}