3 Replies Latest reply on Sep 18, 2011 11:42 PM by felipebutcher

    Getting the connection url from the *-ds.xml file

    mcasperson

      I have a seam application that can be run locally or against a live database. To switch between the two, a different ds.xml file is used. What I need to do is display a warning if the live database is currently configured, which means getting access to the contents of the connection-url tag. How can I access this tag programmatically from a bean or pojo?

        • 1. Re: Getting the connection url from the *-ds.xml file
          tulsidas

          If you are using Hibernate as the JPA provider you can use


          @In EntityManager em;
          
          Session sess = (Session) em.getDelegate();
          Connection conn = sess.connection();
          DatabaseMetaData dbmd = conn.getMetaData();
          String url = dbmd.getUrl();
          



          Or any other useful method in the DatabaseMetaData class

          • 2. Re: Getting the connection url from the *-ds.xml file
            mcasperson

            Turns out calling Session.connection throws an exception. But the following works:


            final Session sess = (Session) entityManager.getDelegate();                    
            sess.doWork(new Work()
                    {
                            public void execute(Connection connection)
                                    throws SQLException
                            {
                                    final DatabaseMetaData dbmd = connection.getMetaData();
                                    final String url = dbmd.getURL();
                            }
                    }              
            );

            • 3. Re: Getting the connection url from the *-ds.xml file
              felipebutcher

              andres quijano. that worked for me.


              seam 2.2.2
              jboss 4.3.2