{"id":329,"date":"2025-09-08T17:07:25","date_gmt":"2025-09-08T17:07:25","guid":{"rendered":"https:\/\/iotnoob.com\/wordpress\/?p=329"},"modified":"2025-09-09T10:08:40","modified_gmt":"2025-09-09T10:08:40","slug":"sql-%e0%b8%aa%e0%b8%b3%e0%b8%ab%e0%b8%a3%e0%b8%b1%e0%b8%9a-select-%e0%b8%88%e0%b8%b2%e0%b8%81-db-%e0%b9%82%e0%b8%94%e0%b8%a2%e0%b9%80%e0%b8%a5%e0%b8%b7%e0%b8%ad%e0%b8%81%e0%b9%80%e0%b8%89%e0%b8%9e","status":"publish","type":"post","link":"https:\/\/iotnoob.com\/wordpress\/2025\/09\/08\/sql-%e0%b8%aa%e0%b8%b3%e0%b8%ab%e0%b8%a3%e0%b8%b1%e0%b8%9a-select-%e0%b8%88%e0%b8%b2%e0%b8%81-db-%e0%b9%82%e0%b8%94%e0%b8%a2%e0%b9%80%e0%b8%a5%e0%b8%b7%e0%b8%ad%e0%b8%81%e0%b9%80%e0%b8%89%e0%b8%9e\/","title":{"rendered":"SQL \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a SELECT \u0e08\u0e32\u0e01 DB \u0e42\u0e14\u0e22\u0e40\u0e25\u0e37\u0e2d\u0e01\u0e40\u0e09\u0e1e\u0e32\u0e30\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e43\u0e19 list"},"content":{"rendered":"\n<p>\u0e16\u0e49\u0e32\u0e40\u0e23\u0e32\u0e21\u0e35 list \u0e2b\u0e23\u0e37\u0e2d array \u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e35\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e04\u0e49\u0e19\u0e2b\u0e32\u0e08\u0e32\u0e01 table \u0e43\u0e19 DB<br>\u0e42\u0e14\u0e22\u0e40\u0e23\u0e32\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23 select \u0e17\u0e31\u0e49\u0e07 table \u0e40\u0e1e\u0e23\u0e32\u0e30\u0e21\u0e31\u0e19\u0e08\u0e30\u0e40\u0e22\u0e2d\u0e30\u0e44\u0e1b<br>\u0e41\u0e25\u0e49\u0e27\u0e40\u0e23\u0e32\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e27\u0e19\u0e25\u0e39\u0e1b select \u0e17\u0e35\u0e25\u0e30\u0e15\u0e31\u0e27 \u0e40\u0e1e\u0e23\u0e32\u0e30\u0e08\u0e30\u0e40\u0e2a\u0e35\u0e22\u0e40\u0e27\u0e25\u0e32\u0e21\u0e32\u0e01\u0e44\u0e1b<\/p>\n\n\n\n<p>\u0e2b\u0e25\u0e31\u0e01\u0e01\u0e32\u0e23 \u0e04\u0e37\u0e2d \u0e40\u0e23\u0e32\u0e43\u0e0a\u0e49 WHERE &#8211; IN \u0e43\u0e19\u0e01\u0e32\u0e23\u0e2a\u0e48\u0e07 list \u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b\u0e17\u0e33 query<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT user_id, username, email\nFROM users\nWHERE username IN ('A', 'B', 'D');<\/pre>\n\n\n\n<p>\u0e17\u0e35\u0e19\u0e35\u0e49 \u0e40\u0e27\u0e25\u0e32\u0e08\u0e30\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\u0e43\u0e19 Java \u0e25\u0e48\u0e30 \u0e40\u0e23\u0e32\u0e08\u0e30\u0e44\u0e21\u0e48\u0e2a\u0e23\u0e49\u0e32\u0e07 string \u0e41\u0e1a\u0e1a (&#8216;A&#8217;, &#8216;B&#8217;, &#8216;D&#8217;) \u0e41\u0e15\u0e48\u0e40\u0e23\u0e32\u0e08\u0e30\u0e2a\u0e48\u0e07 array \u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b\u0e17\u0e31\u0e49\u0e07\u0e2d\u0e31\u0e19\u0e40\u0e25\u0e22<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import java.sql.Connection;\nimport java.sql.PreparedStatement;\nimport java.sql.ResultSet;\nimport java.sql.SQLException;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.stream.Collectors;\n\npublic class SelectWithInClause {\n\n    public void getUsers(List&lt;String> usernames) {\n        if (usernames == null || usernames.isEmpty()) {\n            return; \/\/ \u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e17\u0e33\u0e2d\u0e30\u0e44\u0e23\u0e16\u0e49\u0e32\u0e25\u0e34\u0e2a\u0e15\u0e4c\u0e27\u0e48\u0e32\u0e07\n        }\n\n        \/\/ 1. \u0e2a\u0e23\u0e49\u0e32\u0e07 String \u0e02\u0e2d\u0e07 placeholder \"(?, ?, ?)\"\n        String placeholders = usernames.stream()\n                                       .map(name -> \"?\")\n                                       .collect(Collectors.joining(\", \"));\n\n        \/\/ 2. \u0e2a\u0e23\u0e49\u0e32\u0e07 SQL Query \u0e17\u0e35\u0e48\u0e2a\u0e21\u0e1a\u0e39\u0e23\u0e13\u0e4c\n        String sql = \"SELECT user_id, username, email FROM users WHERE username IN (\" + placeholders + \")\";\n        \n        System.out.println(\"Executing SQL: \" + sql);\n\n        try (Connection conn = getDbConnection(); \/\/ \u0e2a\u0e21\u0e21\u0e15\u0e34\u0e27\u0e48\u0e32\u0e21\u0e35\u0e40\u0e21\u0e18\u0e2d\u0e14\u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d DB\n             PreparedStatement pstmt = conn.prepareStatement(sql)) {\n\n            \/\/ 3. \u0e27\u0e19\u0e25\u0e39\u0e1b\u0e40\u0e1e\u0e37\u0e48\u0e2d\u0e15\u0e31\u0e49\u0e07\u0e04\u0e48\u0e32 parameter \u0e17\u0e35\u0e25\u0e30\u0e15\u0e31\u0e27\n            int index = 1;\n            for (String name : usernames) {\n                pstmt.setString(index++, name);\n            }\n\n            \/\/ 4. \u0e2a\u0e31\u0e48\u0e07\u0e43\u0e2b\u0e49 Query \u0e17\u0e33\u0e07\u0e32\u0e19\n            try (ResultSet rs = pstmt.executeQuery()) {\n                System.out.println(\"\u0e1c\u0e25\u0e25\u0e31\u0e1e\u0e18\u0e4c:\");\n                while (rs.next()) {\n                    System.out.printf(\"ID: %d, Username: %s, Email: %s\\n\",\n                            rs.getInt(\"user_id\"),\n                            rs.getString(\"username\"),\n                            rs.getString(\"email\"));\n                }\n            }\n\n        } catch (SQLException e) {\n            e.printStackTrace();\n        }\n    }\n\n    \/\/ \u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e40\u0e23\u0e35\u0e22\u0e01\u0e43\u0e0a\u0e49\u0e07\u0e32\u0e19\n    public static void main(String[] args) {\n        SelectWithInClause selector = new SelectWithInClause();\n        List&lt;String> namesToFind = Arrays.asList(\"A\", \"B\", \"D\");\n        selector.getUsers(namesToFind);\n    }\n\n    \/\/ \u0e40\u0e21\u0e18\u0e2d\u0e14\u0e08\u0e33\u0e25\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\n    private static Connection getDbConnection() throws SQLException {\n        \/\/ \u0e43\u0e19\u0e42\u0e04\u0e49\u0e14\u0e08\u0e23\u0e34\u0e07 \u0e2a\u0e48\u0e27\u0e19\u0e19\u0e35\u0e49\u0e08\u0e30\u0e40\u0e1b\u0e47\u0e19\u0e01\u0e32\u0e23\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e15\u0e48\u0e2d\u0e10\u0e32\u0e19\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e02\u0e2d\u0e07\u0e04\u0e38\u0e13\n        \/\/ return DriverManager.getConnection(URL, USER, PASS);\n        return null; \/\/ Dummy implementation\n    }\n}<\/pre>\n\n\n\n<p>\u0e15\u0e31\u0e27\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e02\u0e49\u0e32\u0e07\u0e1a\u0e19 \u0e08\u0e30\u0e43\u0e0a\u0e49 preparedStatement <br>\u0e42\u0e14\u0e22\u0e2a\u0e23\u0e49\u0e32\u0e07 place holder \u0e2a\u0e33\u0e2b\u0e23\u0e31\u0e1a array \u0e17\u0e35\u0e48\u0e08\u0e30\u0e43\u0e2a\u0e48\u0e43\u0e19 WHERE &#8211; IN<br>\u0e42\u0e14\u0e22\u0e43\u0e0a\u0e49 stream \u0e43\u0e19\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 \u0e0b\u0e36\u0e48\u0e07\u0e27\u0e34\u0e18\u0e35\u0e01\u0e32\u0e23\u0e04\u0e48\u0e2d\u0e19\u0e02\u0e49\u0e32\u0e07\u0e14\u0e39\u0e14\u0e35\u0e17\u0e35\u0e40\u0e14\u0e35\u0e22\u0e27<br>\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e40\u0e02\u0e35\u0e22\u0e19 code \u0e27\u0e19\u0e25\u0e39\u0e1b\u0e17\u0e35\u0e25\u0e30\u0e15\u0e31\u0e27\u0e40\u0e2d\u0e07<\/p>\n\n\n\n<p>String placeholders = usernames.stream().map(name -> &#8220;?&#8221;).collect(Collectors.joining(&#8220;, &#8220;));<\/p>\n\n\n\n<p>\u0e40\u0e2d\u0e32 ArrayList \u0e21\u0e32\u0e17\u0e33 stream -> \u0e08\u0e32\u0e01\u0e19\u0e31\u0e49\u0e19 map \u0e04\u0e48\u0e32\u0e43\u0e19 stream \u0e17\u0e35\u0e48\u0e15\u0e2d\u0e19\u0e19\u0e35\u0e49\u0e41\u0e17\u0e19\u0e14\u0e49\u0e27\u0e22\u0e15\u0e31\u0e27\u0e41\u0e1b\u0e23 name \u0e43\u0e2b\u0e49\u0e40\u0e1b\u0e47\u0e19 &#8220;?&#8221; -> \u0e08\u0e32\u0e01\u0e19\u0e31\u0e49\u0e19\u0e23\u0e27\u0e1a\u0e40\u0e02\u0e49\u0e32\u0e14\u0e49\u0e27\u0e22\u0e01\u0e31\u0e19 \u0e14\u0e49\u0e27\u0e22 collect \u0e42\u0e14\u0e22\u0e40\u0e0a\u0e37\u0e48\u0e2d\u0e21\u0e01\u0e31\u0e19\u0e14\u0e49\u0e27\u0e22 joining &#8220;,&#8221;<\/p>\n\n\n\n<p>\u0e41\u0e15\u0e48\u0e15\u0e2d\u0e19 set string \u0e40\u0e02\u0e49\u0e32\u0e44\u0e1b\u0e43\u0e19 prepareStatement \u0e22\u0e31\u0e07\u0e15\u0e49\u0e2d\u0e07\u0e27\u0e19\u0e25\u0e39\u0e1b set \u0e2d\u0e22\u0e39\u0e48<\/p>\n\n\n\n<p>int index = 1;<br>for (String name : usernames) {<br>    pstmt.setString(index++, name);<br>}<\/p>\n\n\n\n<p>\u0e01\u0e47\u0e14\u0e39\u0e41\u0e1b\u0e25\u0e01\u0e46\u0e14\u0e35<\/p>\n\n\n\n<p>\u0e41\u0e15\u0e48 preparedStatement \u0e21\u0e31\u0e19\u0e21\u0e35\u0e02\u0e49\u0e2d\u0e14\u0e35\u0e04\u0e37\u0e2d\u0e15\u0e31\u0e27\u0e21\u0e31\u0e19\u0e0a\u0e48\u0e27\u0e22\u0e40\u0e23\u0e37\u0e48\u0e2d\u0e07 security \u0e2d\u0e22\u0e48\u0e32\u0e07\u0e01\u0e32\u0e23\u0e1b\u0e49\u0e2d\u0e07\u0e01\u0e31\u0e19\u0e1e\u0e27\u0e01 Sql Injection<\/p>\n\n\n\n<p>\u0e40\u0e1e\u0e23\u0e32\u0e30 \u0e16\u0e49\u0e32\u0e44\u0e21\u0e48\u0e2d\u0e22\u0e48\u0e32\u0e07\u0e19\u0e31\u0e49\u0e19 \u0e40\u0e23\u0e32\u0e01\u0e47\u0e43\u0e0a\u0e49 stream \u0e43\u0e19\u0e01\u0e32\u0e23\u0e2a\u0e23\u0e49\u0e32\u0e07 query \u0e41\u0e17\u0e19 Place holder \u0e44\u0e1b\u0e40\u0e25\u0e22<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0e16\u0e49\u0e32\u0e40\u0e23\u0e32\u0e21\u0e35 list \u0e2b\u0e23\u0e37\u0e2d array \u0e02\u0e2d\u0e07\u0e02\u0e49\u0e2d\u0e21\u0e39\u0e25\u0e17\u0e35\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e04\u0e49\u0e19\u0e2b\u0e32\u0e08\u0e32\u0e01 table \u0e43\u0e19 DB\u0e42\u0e14\u0e22\u0e40\u0e23\u0e32\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23 select \u0e17\u0e31\u0e49\u0e07 table \u0e40\u0e1e\u0e23\u0e32\u0e30\u0e21\u0e31\u0e19\u0e08\u0e30\u0e40\u0e22\u0e2d\u0e30\u0e44\u0e1b\u0e41\u0e25\u0e49\u0e27\u0e40\u0e23\u0e32\u0e44\u0e21\u0e48\u0e15\u0e49\u0e2d\u0e07\u0e01\u0e32\u0e23\u0e27\u0e19\u0e25\u0e39\u0e1b select \u0e17\u0e35\u0e25\u0e30\u0e15\u0e31\u0e27 \u0e40\u0e1e\u0e23\u0e32\u0e30\u0e08\u0e30\u0e40\u0e2a\u0e35\u0e22\u0e40\u0e27\u0e25\u0e32\u0e21\u0e32\u0e01\u0e44\u0e1b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":339,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-329","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-programming"],"_links":{"self":[{"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/posts\/329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/comments?post=329"}],"version-history":[{"count":1,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":330,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/posts\/329\/revisions\/330"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/media\/339"}],"wp:attachment":[{"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotnoob.com\/wordpress\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}