{"id":6677,"date":"2018-04-30T14:04:32","date_gmt":"2018-04-30T19:04:32","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6677"},"modified":"2018-04-30T14:08:23","modified_gmt":"2018-04-30T19:08:23","slug":"loading-snowflake-from-oracle","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2018\/04\/30\/loading-snowflake-from-oracle\/","title":{"rendered":"Loading snowflake from Oracle"},"content":{"rendered":"<p>Single class to illustrate loading data&#8230;<\/p>\n<pre>\r\nimport java.sql.*;\r\nimport java.util.*;\r\n\r\npublic class loadSnowflake {\r\n  public static void main(String[] args) throws Exception {\r\n    Class.forName(\"oracle.jdbc.driver.OracleDriver\");\r\n    Class.forName(\"com.snowflake.client.jdbc.SnowflakeDriver\");\r\n    Properties properties = new Properties();\r\n    properties.put(\"user\", \"showard\");\r\n    properties.put(\"password\", \"*****\");\r\n    properties.put(\"account\", \"rcaccount#\");\r\n    properties.put(\"schema\", \"PUBLIC\");\r\n    Connection connection = DriverManager.getConnection(\"jdbc:snowflake:\/\/rcaccount#.us-east-1.snowflakecomputing.com?db=SDHPOC\", properties);\r\n    Connection connOra = DriverManager.getConnection(\"jdbc:oracle:thin:showard\/****@orahost:1521\/service.domain\");\r\n    ResultSet rst = connOra.createStatement().executeQuery(\"select * from sa_tran_head where tran_datetime > sysdate - 7 and rownum <= 1000\");\r\n    ResultSetMetaData rsmd = rst.getMetaData();\r\n    PreparedStatement snowflakePst = connection.prepareStatement(\"insert into snowflake_sa_tran_head values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,\r\n                                                                                                            ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)\");\r\n    int i = 0;\r\n    while (rst.next()) {\r\n      for (int j = 1; j <= rsmd.getColumnCount(); j++) {\r\n\tif (rsmd.getColumnTypeName(j).equals(\"NUMBER\")) {\r\n          snowflakePst.setLong(j,rst.getLong(j));\r\n\t}\r\n\telse if (rsmd.getColumnTypeName(j).equals(\"DATE\")) {\r\n          snowflakePst.setDate(j,rst.getDate(j));\r\n\t}\r\n\tif (rsmd.getColumnTypeName(j).equals(\"VARCHAR2\")) {\r\n          snowflakePst.setString(j,rst.getString(j));\r\n\t}\r\n      }\r\n      snowflakePst.addBatch();\r\n      if (++i % 1000 == 0) {\r\n        System.out.println(\"Starting to execute batch (\" + i + \") at \" + new java.util.Date());\r\n   \tsnowflakePst.executeBatch();\r\n\tconnection.commit();\r\n        System.out.println(\"Finished batch (\" + i + \") at \" + new java.util.Date());\r\n      }\r\n    }\r\n    try {\r\n      snowflakePst.executeBatch();\r\n    }\r\n    catch (Exception e) {\r\n      System.out.println(e.getMessage());\r\n    }\r\n    connection.commit();\r\n    connection.createStatement().execute(\"truncate table if exists snowflake_sa_tran_head\");\r\n    System.out.println(\"loaded then truncated data\");\r\n    \/\/too lazy to close, doesn't really matter since JVM is exiting...\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Single class to illustrate loading data&#8230; import java.sql.*; import java.util.*; public class loadSnowflake { public static void main(String[] args) throws Exception { Class.forName(&#8220;oracle.jdbc.driver.OracleDriver&#8221;); Class.forName(&#8220;com.snowflake.client.jdbc.SnowflakeDriver&#8221;); Properties properties = new Properties(); properties.put(&#8220;user&#8221;, &#8220;showard&#8221;); properties.put(&#8220;password&#8221;, &#8220;*****&#8221;); properties.put(&#8220;account&#8221;, &#8220;rcaccount#&#8221;); properties.put(&#8220;schema&#8221;, &#8220;PUBLIC&#8221;); Connection connection =&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2018\/04\/30\/loading-snowflake-from-oracle\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[101,102],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6677"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6677"}],"version-history":[{"count":3,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6677\/revisions"}],"predecessor-version":[{"id":6680,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6677\/revisions\/6680"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6677"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}