users@glassfish.java.net

Re: Wrong XAState: 0

From: <glassfish_at_javadesktop.org>
Date: Fri, 20 Feb 2009 17:55:19 PST

I don't know what you exactly mean. Here my code for jdbc lookup and creation of a database connection:
[code]
// --------------------------------------------------------------------------------------------------------------------------------------------------
public class DbManager {
    
    @Resource(name = "jdbc/Postgres")
    private DataSource db = null;
    private LogManager log = null;
    private Utils utils = null;
    private static DbManager instance = null;
    private String defaultDate = "2222-12-12 12:12:12.1"; //have to use this instead of NULL due to data base restrictions
            
    /** Creates a new instance of DbManager */
    protected DbManager() {
        log = new LogManager();
        log.traceMethodeDetails();
        
        utils = new Utils();
        
        Context c;
        try {
            c = new InitialContext();
            db = (DataSource) c.lookup("jdbc/Postgres");
            log.debug("COSTO: lookup of datasource jdbc/Postgres successful");
        } catch (NamingException ex) {
            log.debug("Could not lookup JNDI name...("+ex.getMessage()+")");
        }
    }
    
    public static DbManager getInstance() {
        if(instance == null) {
            instance = new DbManager();
        }
        return instance;
    }
    
    // ---- reserves a connection from db connection pool and returns it
    private Connection getConnection()
    {
        Connection con = null;
        try {
            con = db.getConnection();
            con.setAutoCommit(true);
        } catch (SQLException ex) {
            log.internalError("Could not get database connection... ("+ex.getMessage()+")");
        }

        return con;
    }

    // ---- releases a previous requested connection from the connection pool
    void releaseConnection(Connection con) {
        try{
            if ((con != null) && (con.isClosed() == false)){
                con.close();
                con = null;
            }
        } catch (SQLException ex) {
            log.internalError("Could not close database connection... ("+ex.getMessage()+")");
        }
    }
[/code]

Thanks
[Message sent by forum member 'glassfox' (glassfox)]

http://forums.java.net/jive/thread.jspa?messageID=333207