{"id":1265,"date":"2018-04-22T12:31:43","date_gmt":"2018-04-22T03:31:43","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=1265"},"modified":"2018-04-23T00:47:23","modified_gmt":"2018-04-22T15:47:23","slug":"%e3%80%90java%e3%80%91jdbc%e3%83%97%e3%83%ad%e3%82%b0%e3%83%a9%e3%83%a0%e3%82%92%e7%90%86%e8%a7%a3%e3%81%99%e3%82%8b%e3%80%82","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=1265","title":{"rendered":"\u3010Java\u3011JDBC\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7406\u89e3\u3059\u308b\u3002"},"content":{"rendered":"<p>Java\u304b\u3089\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u3001JDBC\u3092\u4f7f\u3046\u3068\u8aac\u660e\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>JDBC\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u57fa\u672c\u30af\u30e9\u30b9<\/h2>\n<table>\n<tbody>\n<tr>\n<th>\u30af\u30e9\u30b9<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>DriverManager<\/td>\n<td>JDBC\u30c9\u30e9\u30a4\u30d0\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9\u3001Connection\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>Connection<\/td>\n<td>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3068\u306e\u300c\u63a5\u7d9a\u300d\u3092\u8868\u3059\u30af\u30e9\u30b9\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u3053\u304b\u3089Statement\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>Statement<\/td>\n<td>SQL\u3092\u767a\u884c\u3059\u308b\u305f\u3081\u306e\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>ResultSet<\/td>\n<td>SELECT\u6587\u3092\u767a\u884c\u3057\u305f\u969b\u306e\u3001\u7d50\u679c\u3092\u8868\u3059\u30af\u30e9\u30b9\u3067\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>SQLException<\/td>\n<td>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u95a2\u3059\u308b\u30a8\u30e9\u30fc\u3092\u63d0\u4f9b\u3059\u308b\u30af\u30e9\u30b9\u3067\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>JDBC\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u6d41\u308c<\/h2>\n<ol>\n<li>Class.forName()\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308a\u3001JDBC\u30c9\u30e9\u30a4\u30d0\u3092\u30ed\u30fc\u30c9\u3059\u308b\u3002<\/li>\n<li>DriverManager.getConnection()\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308a\u3001Connection\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u3002<\/li>\n<li>Connection.createStatement()\u30e1\u30bd\u30c3\u30c9\u306b\u3088\u308a\u3001Statement\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u3002<\/li>\n<li>SQL\u6587\u3092\u5b9f\u884c\u3059\u308b\u3002(\u66f4\u65b0\u7cfb\u3067\u3042\u308c\u3070\u3001executeUpdate()\u30e1\u30bd\u30c3\u30c9\u3001SELECT\u6587\u3067\u3042\u308c\u3070\u3001executeQuery()\u30e1\u30bd\u30c3\u30c9\u306b\u306a\u308a\u307e\u3059\u3002<\/li>\n<li>close()\u30e1\u30bd\u30c3\u30c9\u306b\u3066\u30b3\u30cd\u30af\u30b7\u30e7\u30f3\u3092\u9589\u3058\u308b\u3002<\/li>\n<\/ol>\n<h2>Class.forName()\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066<\/h2>\n<p>Oracle\u3067\u3042\u308c\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nClass.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);\r\n<\/pre>\n<p>\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306f\u3001JDBC\u30c9\u30e9\u30a4\u30d0\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u4ed8\u30af\u30e9\u30b9\u540d\u3092\u6307\u5b9a\u3057\u3066\u3001<span style=\"color: #ff0000;\"><strong>JDBC\u30c9\u30e9\u30a4\u30d0\u3092\u30ed\u30fc\u30c9\u3055\u305b\u308b\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u5229\u7528\u3059\u308bRDB\u306b\u3088\u3063\u3066\u30d1\u30c3\u30b1\u30fc\u30b8\u30af\u30e9\u30b9\u540d\u3092\u5909\u3048\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u304c\u3001Oracle\u306e\u5834\u5408\u306f\u3001<strong>\u300coracle.jdbc.driver.OracleDriver\u300d<\/strong>\u3068\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<h3>\u5b9f\u969b\u306e\u6240<\/h3>\n<p>Class.forName()\u30e1\u30bd\u30c3\u30c9\u306e\u547c\u3073\u51fa\u3057\u306f\u3001<span style=\"color: #ff0000;\"><strong>JVM\u5b9f\u884c\u4e2d\u306b1\u56de\u3060\u3051\u547c\u3073\u51fa\u305b\u3070\u3088\u304f\u4f55\u5ea6\u3082\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/span>\u305f\u3060\u3001\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u4f55\u5ea6\u3082\u547c\u3073\u51fa\u3055\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>DriverManager.getConnection()\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066<\/h2>\n<p>Oracle\u3067\u3042\u308c\u3070\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/\u30db\u30b9\u30c8\u540d\r\nString hostname = &quot;localhost&quot;;\r\n\/\/SID\r\nString sid = &quot;orcl&quot;;\r\n\/\/\u30e6\u30fc\u30b6\u30fc\u540d\r\nString username = &quot;orauser&quot;;\r\n\/\/\u30d1\u30b9\u30ef\u30fc\u30c9\r\nString passwd = &quot;orapass&quot;;\r\n\r\nConnection con = DriverManager.getConnection(&quot;jdbc:oracle:thin:@&quot; + hostname + &quot;:1521:&quot; + sid,username,passwd);\r\n<\/pre>\n<table>\n<tbody>\n<tr>\n<th>\u5f15\u6570<\/th>\n<th>\u8aac\u660e<\/th>\n<\/tr>\n<tr>\n<td>URL(jdbc:oracle:thin:@localhost:1521:orcl)<\/td>\n<td>JDBC\u306eURL(\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u5834\u6240)\u3092\u793a\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u30e6\u30fc\u30b6\u30fc\u540d(orauser)<\/td>\n<td>DB\u63a5\u7d9a\u306e\u30e6\u30fc\u30b6\u30fc\u540d\u3092\u793a\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u30d1\u30b9\u30ef\u30fc\u30c9(passwd)<\/td>\n<td>DB\u63a5\u7d9a\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u793a\u3057\u307e\u3059\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Connection.createStatement()\u30e1\u30bd\u30c3\u30c9<\/h2>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nStatement smt = con.createStatement();\r\n<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308c\u3070\u3001Statement\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u826f\u304f\u4f7f\u308f\u308c\u308b\u306e\u306f\u3001Statement\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3067\u306f\u306a\u304f\u3001\u305d\u306e\u30b5\u30d6\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u3067\u3042\u308b\u3088\u308a\u9ad8\u6a5f\u80fd\u306a\u300c<strong>PreparedStatement<\/strong>\u300d\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u4e0b\u8a18\u306e\u8a18\u4e8b\u3067\u3001\u4f7f\u3044\u65b9\u306f\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"jlSSLRR1RT\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=1288\">\u3010Java\u3011PreparedStatement\u306b\u3088\u308bINSERT\u6587\u306e\u5b9f\u884c<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=1288&#038;embed=true#?secret=jlSSLRR1RT\" data-secret=\"jlSSLRR1RT\" width=\"500\" height=\"282\" title=\"&#8220;\u3010Java\u3011PreparedStatement\u306b\u3088\u308bINSERT\u6587\u306e\u5b9f\u884c&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h2>close()\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066<\/h2>\n<p>\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3078\u306e\u63a5\u7d9a\u3092<span style=\"color: #ff0000;\"><strong>\u660e\u793a\u7684\u306b\u5207\u65ad<\/strong><\/span>\u3057\u307e\u3059\u3002\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u547c\u3073\u51fa\u3057\u306e\u969b\u306f\u3001\u5fc5\u305a\u3053\u308c\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nsmt.close();\r\ncon.close();\r\n<\/pre>\n<p>\u306a\u304a\u3001<strong>ResultSet\u306b\u95a2\u3057\u3066\u306f\u3001Statement\u3092close\u3057\u305f\u969b\u306b\u3001\u81ea\u52d5\u3067\u89e3\u653e\u3055\u308c\u308b\u306e\u3067\u660e\u793a\u7684\u306a\u89e3\u653e\u306f\u5fc5\u8981\u306a\u3044<\/strong>\u3067\u3059\u3002\uff08\u305f\u3060\u3001JDBC\u30c9\u30e9\u30a4\u30d0\u306b\u3088\u3063\u3066\u306f\u3001Statement\u3092close()\u3057\u3066\u3082\u3001ResultSet\u304cclose\u3055\u308c\u306a\u3044\u3082\u306e\u3082\u3042\u308a\u307e\u3057\u305f\u306e\u3067\u3001\u305d\u306e\u540d\u6b8b\u3067\u3001\u6b8b\u3063\u3066\u3044\u308b\u30b7\u30b9\u30c6\u30e0\u306f\u3042\u308b\u5834\u5408\u3082\u3042\u308a\u307e\u3059\u3002\uff09<\/p>\n<h3>\u306a\u305c\u3001\u660e\u793a\u7684\u306b\u5207\u65ad\u3092\u3059\u308b\u306e\u304b\uff1f<\/h3>\n<p>Java\u306b\u306f\u3001<strong>\u30ac\u30d9\u30fc\u30b8\u30b3\u30ec\u30af\u30b7\u30e7\u30f3<\/strong>\u3068\u3044\u3046\u6a5f\u80fd\u3067\u30e1\u30e2\u30ea\u3092\u81ea\u52d5\u7684\u306b\u89e3\u653e\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3001\u5225\u306b\u660e\u793a\u7684\u306b\u89e3\u653e\u3059\u308b\u5fc5\u8981\u306f\u306a\u3044\u306e\u3067\u306f\uff1f\u3068\u601d\u308f\u308c\u308b\u65b9\u3082\u3044\u3089\u3063\u3057\u3083\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u901a\u5e38\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5834\u5408\u3067\u3042\u308c\u3070\u3001\u5927\u4e08\u592b\u3067\u3059\u304c\u3001<span style=\"color: #ff0000;\"><strong>\u30d5\u30a1\u30a4\u30eb\u3084DB\u7b49\u306e\u5916\u90e8\u30ea\u30bd\u30fc\u30b9\u3092\u30ea\u30ea\u30fc\u30b9\u3059\u308b\u5834\u5408\u306f\u3001\u660e\u793a\u7684\u306a\u89e3\u653e\u304c\u5fc5\u8981<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u56de\u304f\u3089\u3044\u306eSQL\u3092\u767a\u884c\u3059\u308b\u5358\u7d14\u306a\u30a2\u30d7\u30ea\u306a\u3089\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001Web\u30a2\u30d7\u30ea\u306e\u3088\u3046\u306b\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u8d77\u52d5\u3057\u3063\u3071\u306a\u3057\u3067\u3001<span style=\"color: #ff0000;\"><strong>\u983b\u7e41\u306bSQL\u304c\u767a\u884c\u3055\u308c\u308b\u30b7\u30b9\u30c6\u30e0\u306e\u5834\u5408\u306f\u3001\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u4f4e\u4e0b\u3084\u3001\u60aa\u304f\u306a\u308b\u3068\u30cf\u30f3\u30b0\u30a2\u30c3\u30d7\u3084\u3001\u505c\u6b62\u3092\u5f15\u304d\u8d77\u3053\u3057\u304b\u306d\u306a\u3044<\/strong><\/span>\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Java\u304b\u3089\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306b\u63a5\u7d9a\u3059\u308b\u306b\u306f\u3001JDBC\u3092\u4f7f\u3046\u3068\u8aac\u660e\u3055\u305b\u3066\u9802\u304d\u307e\u3057\u305f\u3002 JDBC\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u57fa\u672c\u30af\u30e9\u30b9 \u30af\u30e9\u30b9 \u8aac\u660e DriverManager JDBC\u30c9\u30e9\u30a4\u30d0\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081\u306e\u30af\u30e9\u30b9\u3001Connection\u30aa\u30d6 [&hellip;]","protected":false},"author":1,"featured_media":1379,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,20],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1265"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1265"}],"version-history":[{"count":15,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1265\/revisions"}],"predecessor-version":[{"id":1335,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/1265\/revisions\/1335"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/media\/1379"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1265"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}