{"id":1713,"date":"2010-06-02T23:05:11","date_gmt":"2010-06-02T15:05:11","guid":{"rendered":"\/?p=1713"},"modified":"2010-06-02T23:05:11","modified_gmt":"2010-06-02T15:05:11","slug":"1713","status":"publish","type":"post","link":"https:\/\/www.justzz.com\/spec\/1713.html","title":{"rendered":"JNDI\u8c03\u7528\u6570\u636e\u6e90\u4ee3\u7801\u7247\u6bb5"},"content":{"rendered":"<div>\n<p><strong>\u4e00\u3001\u8c03\u7528weblogic\u6570\u636e\u6e90\u7684JNDI\u4ee3\u7801\u7247\u6bb5<\/strong><\/p>\n<p><strong>i<\/strong>mport java.sql.Connection;<br \/>\nimport java.sql.ResultSet;<br \/>\nimport java.sql.Statement;<br \/>\nimport java.util.Hashtable;<br \/>\nimport javax.naming.Context;<br \/>\nimport javax.naming.InitialContext;<br \/>\nimport javax.sql.DataSource;<br \/>\npublic class Test {<br \/>\npublic static void main(String[] args) throws Exception {<br \/>\nHashtable ht = new Hashtable();<br \/>\nht.put(Context.INITIAL_CONTEXT_FACTORY,<br \/>\n\"weblogic.jndi.WLInitialContextFactory\");<br \/>\nht.put(Context.PROVIDER_URL, \"t3:\/\/localhost:7001\");<br \/>\nContext ctx = new InitialContext(ht);<br \/>\n\/\/Weblogic \u6570\u636e\u6e90\u540d\u79f0\uff1aOra_ds<br \/>\nDataSource ds = (DataSource) ctx.lookup(\"Ora_ds\");<br \/>\nConnection con = ds.getConnection();<br \/>\n......<br \/>\n}<br \/>\n}<\/p>\n<p><strong>\u4e8c\u3001\u8c03\u7528TOMCAT\u6570\u636e\u6e90\u7684JNDI\u4ee3\u7801\u7247\u6bb5<\/strong><\/p>\n<p><strong>i<\/strong>mport java.sql.Connection;<br \/>\nimport javax.naming.Context;<br \/>\nimport javax.naming.InitialContext;<br \/>\nimport javax.sql.DataSource;<br \/>\npublic class Test {<br \/>\npublic static void main(String[] args) throws Exception {<br \/>\nContext initCtx = new InitialContext();<br \/>\n\/\/Tomcat \u6570\u636e\u6e90\u540d\u79f0\uff1ajdbc\/Ora_ds<br \/>\nDataSource ds = (DataSource) initCtx.lookup\u00a0(\"java:comp\/env\/jdbc\/Ora_ds\");<br \/>\nConnection con = ds.getConnection();<br \/>\n......<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u8c03\u7528weblogic\u6570\u636e\u6e90\u7684JNDI\u4ee3\u7801\u7247\u6bb5 import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.H&hellip;<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-1713","post","type-post","status-publish","format-standard","hentry","category-t"],"_links":{"self":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/comments?post=1713"}],"version-history":[{"count":0,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/posts\/1713\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/media?parent=1713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/categories?post=1713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.justzz.com\/spec\/wp-json\/wp\/v2\/tags?post=1713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}