{"id":5846,"date":"2016-10-10T08:08:54","date_gmt":"2016-10-10T13:08:54","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=5846"},"modified":"2016-10-10T08:09:48","modified_gmt":"2016-10-10T13:09:48","slug":"oracle-global-temporary-table-and-connection-pool","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2016\/10\/10\/oracle-global-temporary-table-and-connection-pool\/","title":{"rendered":"Oracle global temporary table and connection pool"},"content":{"rendered":"<p>Our question was what happens to the rows in a global temporary table when populated from a session obtained from a connection pool.  Are they still there for the next application user to borrow the same session from the pool?<\/p>\n<p>The rows are retained across connection pool reserved sessions if the table is configured as &#8220;on commit preserve rows&#8221;.  <\/p>\n<p>In other words, if user A checks connection 4 out of the pool, adds rows to a global temporary table, checks the connection back in, and user B then checks connection 4 out of the pool, the rows will be visible to user B by default.  The only way to get around this is either configure the table as &#8220;on commit delete rows&#8221; (the default), or otherwise remove the rows, such truncate the table at the start of user B&#8217;s session.<\/p>\n<p>The page below will prove this.  Repeated requests will show an increasing number of rows in the pool, even though the connection was &#8220;closed&#8221; when it was returned to the pool.  Perhaps other connection pool implementations allow you to physically close the connection.<\/p>\n<pre>\r\n<%@ page import=\"java.sql.*\"%>\r\n<%@ page import=\"javax.sql.*\"%>\r\n<%@ page import=\"javax.naming.*\"%>\r\n<%@ page import=\"weblogic.logging.*\"%>\r\n\r\n<%\r\ntry {\r\n\u00a0 InitialContext ic = new InitialContext();\r\n\u00a0 DataSource ds = (DataSource)ic.lookup(\"jdbc\/test\");\r\n\u00a0 Connection conn = ds.getConnection();\r\n\u00a0 Statement stm = conn.createStatement();\r\n\u00a0 ResultSet rst = stm.executeQuery(\"select * from t2\");\r\n\u00a0 while (rst.next()) {\r\n\u00a0\u00a0\u00a0 out.println(\"before t2 has this row \" + rst.getString(1) + \"<br>\");\r\n\u00a0 }\r\n\u00a0 stm.execute(\"insert into t2 values(1)\");\r\n\u00a0 conn.close();\r\n\u00a0 conn = ds.getConnection();\r\n\u00a0 stm = conn.createStatement();\r\n\u00a0 rst = stm.executeQuery(\"select * from t2\");\r\n\u00a0 while (rst.next()) {\r\n\u00a0\u00a0\u00a0 out.println(\"before commit t2 has this row \" + rst.getString(1) + \"<br>\");\r\n\u00a0 }\r\n\u00a0 conn.commit();\r\n\u00a0 rst = stm.executeQuery(\"select * from t2\");\r\n\u00a0 while (rst.next()) {\r\n\u00a0\u00a0\u00a0 out.println(\"after commit t2 has this row \" + rst.getString(1) + \"<br>\");\r\n\u00a0 }\r\n\u00a0 conn.close();\r\n}\r\ncatch (Exception e) {\r\n\u00a0 out.println(e.getMessage());\r\n}\r\n%>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Our question was what happens to the rows in a global temporary table when populated from a session obtained from a connection pool. Are they still there for the next application user to borrow the same session from the pool?&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2016\/10\/10\/oracle-global-temporary-table-and-connection-pool\/\">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":[48,19,22,52],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5846"}],"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=5846"}],"version-history":[{"count":3,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5846\/revisions"}],"predecessor-version":[{"id":5849,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/5846\/revisions\/5849"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=5846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=5846"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=5846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}