tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amol Chaudhari" <avchaudh...@gmail.com>
Subject Re: Cannot create resource instance
Date Mon, 30 Jul 2007 13:36:50 GMT
Chris,
Thanks for the reply.
Here's my complete btnSave_action method :-
public String btnSave_action() {
        System.out.println("in btnSave_action...");
        UserTransaction userTransaction = null;
        try {
            Context jndiContextRoot = new InitialContext();
            userTransaction = (UserTransaction)
jndiContextRoot.lookup("java:comp/UserTransaction");
        } catch (NamingException ne) {
            System.out.println("Exception occurred while
UserTransaction Initial Context lookup");
            ne.printStackTrace();
        }
        Connection conn = createConnection();
        if(conn != null) {
            CallableStatement stmt = null;
            try {
            userTransaction.begin();

                System.out.println("Got the Connection...");

                stmt = getCallableStatement(conn);
                System.out.println("Got the callable statement");
                if(stmt != null) {
                    System.out.println("Statement not null...");
                    execute(stmt);
                    System.out.println("Executed Statement");
                }
            userTransaction.commit();
            } catch (Exception ex) {
                System.out.println("Exception Occurred.. ");
            try {
                userTransaction.rollback();
            } catch (SystemException se) {
                System.out.println("Exception occurred while rolling
back the transaction");
            }
            } finally {
                try {
                    stmt.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
                closeConnection(conn);
            }
            System.out.println("Connection closed...");
        } else {
            System.out.println("The connection can not be created.");
        }
        return null;
    }

If I comment out the UserTransaction part from the above code, things
work perfectly fine.
Here you may say that its not necessary to use it. But this is my
sample application, built simply to localize the problem. In my
project it is necessary to use it.


Also following is my configuration for the JNDI datasource:

<Context path="/Student">
    <Resource auth="Container"
driverClassName="com.ibm.db2.jcc.DB2Driver" maxActive="20"
maxIdle="10" maxWait="-1" name="jdbc/ACM" password="db2inst"
type="javax.sql.DataSource"
url="jdbc:db2://192.168.11.103:50001/AMOL2" username="db2inst"/>
</Context>



On 7/28/07, Christopher Schultz <chris@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Amol,
>
> Amol Chaudhari wrote:
> > Can't any of the gurus help me on this?
>
> Perhaps. Can you post the code you are using near this line of code:
>
> test.Student.btnSave_action(Student.java:593)
>
> Also describe how you are configuring your JNDI DataSource. In fact,
> please include your DataSource configuration.
>
> This problem (misconfigured JNDI DataSource) happens to a lot of people,
> and it's usually something simple but takes a while to figure out.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGqjqe9CaO5/Lv0PARAkkyAJ9k18Rgm6D/+DvbU1QcibETJoglKACeL1SL
> QgUI5aL4UkWB/iL66fmmljk=
> =TuUz
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message