[jboss-user] [Datasource Configuration] - JBoss AS 7 - Datasource configuration for postgres

Pirabu Govindaraj do-not-reply at jboss.com
Wed Jul 20 06:20:01 EDT 2011


Pirabu Govindaraj [http://community.jboss.org/people/pirabug] modified the document:

"JBoss AS 7 - Datasource configuration for postgres"

To view the document, visit: http://community.jboss.org/docs/DOC-17064

--------------------------------------------------------------
Hi
     This Article i describe how to create Datasource in JBoss AS 7. 

If you are using the 1.6 JVM, then you should Download *JDBC4 postgresql Driver.*

* *Install the JDBC4 postgresql Driver as a JBoss 7 deployment*

* *After downloading postgressql driver jar file. just move the* *postgressql driver jar file into* *Jboss 7 installation directory under standalone/deployments (*jboss-as-web-7.0.0.Final/standalone/deployments*).*
* *Restart your jboss server*
* Then go to the url and type  http://localhost:8080/ http://localhost:8080/
* click Administration console.
 http://localhost:8080/console  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16754/450-244/jbossAdmin.png 
In Jboss  Administration console you can press New datasource button, enter datasource name and jndi name then click next button.
 http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16755/step1.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16755/450-253/step1.png 
step 2 : select postgresql driver. click Next

 http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16756/step2.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16756/450-254/step2.png 
Step 3:  enter connection URL jdbc:postgresql://localhost:5432/template1 , Username and Password.

 http://community.jboss.org/servlet/JiveServlet/showImage/102-17064-1-16757/step3.png  http://community.jboss.org/servlet/JiveServlet/downloadImage/102-17064-1-16757/450-253/step3.png 
finally click Done.


h3. Testing the Postgressql Datasource 
Using the test client you may now verify the proper installation of your datasource. 

When testing a newly configured datasource we suggest using some very basic JDBC client code embedded in a JSP page  client.jsp

<%@page
    import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"%>

<%
        DataSource ds = null;
        Connection con = null;
        Statement stmt = null;
        InitialContext ic;
        try {
            ic = new InitialContext();
            ds = (DataSource) ic.lookup("java:/SampleDS");

            con = ds.getConnection();
            stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery("select * from login");
            while (rs.next()) {
                out.println("<br> " + rs.getString("username") + " | "
                        + rs.getString("password"));
            }
            rs.close();
            stmt.close();
        } catch (Exception e) {
            out.println("Exception thrown ");
            e.printStackTrace();
        } finally {
            if (con != null) {
                con.close();
            }
        }
    %>
--------------------------------------------------------------

Comment by going to Community
[http://community.jboss.org/docs/DOC-17064]

Create a new document in Datasource Configuration at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2077]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110720/b749685d/attachment-0001.html 


More information about the jboss-user mailing list