<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    JBoss AS 7 - Datasource configuration for postgres
</h3>
<span style="margin-bottom: 10px;">
    modified by <a href="http://community.jboss.org/people/pirabug">Pirabu Govindaraj</a> in <i>Datasource Configuration</i> - <a href="http://community.jboss.org/docs/DOC-17064">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi</p><p>&#160;&#160;&#160;&#160; This Article i describe how to create Datasource in JBoss AS 7. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>If you are using the 1.6 JVM, then you should Download <strong>JDBC4 postgresql Driver.</strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li style="text-align: start;"><strong>Install the JDBC4 postgresql Driver as a JBoss 7 deployment</strong></li></ul><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ul><li style="text-align: start;"><strong>After downloading postgressql driver jar file. just move the </strong><strong>postgressql driver jar file into </strong><strong>Jboss 7 installation directory under standalone/deployments (</strong>jboss-as-web-7.0.0.Final/standalone/deployments<strong>).</strong></li><li style="text-align: start;"><strong>Restart your jboss server</strong></li><li style="text-align: start;"><span>Then go to the url and type </span><a class="jive-link-external-small" href="http://localhost:8080/" target="_blank">http://localhost:8080/</a></li><li style="text-align: start;">click Administration console.</li></ul><p style="text-align: start;"><a href="http://localhost:8080/console"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16754/450-244/jbossAdmin.png </span></a></p><p style="text-align: start;">In Jboss&#160; Administration console you can press New datasource button, enter datasource name and jndi name then click next button.</p><p style="text-align: start;"><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16755/step1.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16755/450-253/step1.png </span></a></p><p style="text-align: start;">step 2 : select postgresql driver. click Next</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;"><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16756/step2.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16756/450-254/step2.png </span></a></p><p style="text-align: start;">Step 3:&#160; enter connection URL jdbc:postgresql://localhost:5432/template1 , Username and Password.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="text-align: start;"><a href="http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16757/step3.png"><span> http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16757/450-253/step3.png </span></a></p><p style="text-align: start;">finally click Done.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><h3 class="title">Testing the Postgressql Datasource </h3><p><a class="jive-link-anchor-small">Using the test client</a> you may now verify the proper installation of your datasource. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><a class="jive-link-anchor-small">When testing a newly configured datasource we suggest using some very basic JDBC client code embedded in a JSP page&#160; client.jsp</a></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;%@page</p><p>&#160;&#160;&#160; import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"%&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;%</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; DataSource ds = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Connection con = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Statement stmt = null;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitialContext ic;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ic = new InitialContext();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ds = (DataSource) ic.lookup("java:/SampleDS");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; con = ds.getConnection();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; stmt = con.createStatement();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ResultSet rs = stmt.executeQuery("select * from login");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; while (rs.next()) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; out.println("&lt;br&gt; " + rs.getString("username") + " | "</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; + rs.getString("password"));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; rs.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; stmt.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Exception e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; out.println("Exception thrown ");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; e.printStackTrace();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } finally {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (con != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; con.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; %&gt;</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-17064">going to Community</a></p>

        <p style="margin: 0;">Create a new document in Datasource Configuration at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2077">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>