<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA["Using a DataSource (JNDI Datasource HOW-TO) example" 主题的最后发表文章]]></title>
		<link>http://www.trydone.com/posts/list/3.page</link>
		<description><![CDATA[最后发表在 "Using a DataSource (JNDI Datasource HOW-TO) example" 主题的信息]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Using a DataSource (JNDI Datasource HOW-TO) example</title>
				<description><![CDATA[ [code=html]&lt;%@page import="java.sql.*, javax.sql.*, javax.naming.*"%&gt;<br /> &lt;html&gt;<br /> &lt;head&gt;<br /> &lt;title&gt;Using a DataSource&lt;/title&gt;<br /> &lt;/head&gt;<br /> &lt;body&gt;<br /> &lt;h1&gt;Using a DataSource&lt;/h1&gt;<br /> &lt;%<br />     DataSource ds = null;<br />     Connection conn = null;<br />     ResultSet result = null;<br />     Statement stmt = null;<br />     ResultSetMetaData rsmd = null;<br />     try{<br />       Context context = new InitialContext();<br />       Context envCtx = (Context) context.lookup("java:comp/env");<br />       ds =  (DataSource)envCtx.lookup("jdbc/address");<br />       if (ds != null) {<br />         conn = ds.getConnection();<br />         stmt = conn.createStatement();<br />         result = stmt.executeQuery("SELECT * FROM AddressList");<br />        }<br />      }<br />      catch (SQLException e) {<br />         System.out.println("Error occurred " + e);<br />       }<br />       int columns=0;<br />       try {<br />         rsmd = result.getMetaData();<br />         columns = rsmd.getColumnCount();<br />       }<br />       catch (SQLException e) {<br />          System.out.println("Error occurred " + e);<br />       }<br />  %&gt;<br />  &lt;table width="90%" border="1"&gt;<br />    &lt;tr&gt;<br />    &lt;% // write out the header cells containing the column labels<br />       try {<br />          for (int i=1; i&lt;=columns; i++) {<br />               out.write("&lt;th&gt;" + rsmd.getColumnLabel(i) + "&lt;/th&gt;");<br />          }<br />    %&gt;<br />    &lt;/tr&gt;<br />    &lt;% // now write out one row for each entry in the database table<br />          while (result.next()) {<br />             out.write("&lt;tr&gt;");<br />             for (int i=1; i&lt;=columns; i++) {<br />               out.write("&lt;td&gt;" + result.getString(i) + "&lt;/td&gt;");<br />             }<br />             out.write("&lt;/tr&gt;");<br />          }<br />  <br />          // close the connection, resultset, and the statement<br />          result.close();<br />          stmt.close();<br />          conn.close();<br />       } // end of the try block<br />       catch (SQLException e) {<br />          System.out.println("Error " + e);<br />       }<br />       // ensure everything is closed<br />     finally {<br />      try {<br />        if (stmt != null)<br />         stmt.close();<br />        }  catch (SQLException e) {}<br />        try {<br />         if (conn != null)<br />          conn.close();<br />         } catch (SQLException e) {}<br />     }<br />  <br />     %&gt;<br /> &lt;/table&gt;<br /> &lt;/body&gt;<br /> &lt;/html&gt;<br /> [/code]]]></description>
				<guid isPermaLink="true">http://www.trydone.com/posts/preList/56/81.page</guid>
				<link>http://www.trydone.com/posts/preList/56/81.page</link>
				<pubDate><![CDATA[Sat, 3 Mar 2007 01:09:40]]> GMT</pubDate>
				<author><![CDATA[ Admin]]></author>
			</item>
	</channel>
</rss>