Thanks. If I use MysqlDataSource, there is no problem. But my problem is how to
use MySQL's XA in
tomcat environment. Who has this example? I have done a test to check MySQL
XA's function, but
the result is failed. So I wonder if MySQL has real XA to operate database.
Especial how to fix
"Lock wait timeout exceeded; try restarting transaction" problem ? Sorry I
past the previous mail
in the end for reference,in wich "Lock wait timeout exceeded" occured.
Wang Jun
--- Lin Sun <[EMAIL PROTECTED]>写道:
> I have a simple jsp script that can lookup a server-wide datasource. In
> the jsp, I don't have to specify the driver or make the connection. I only
> need to perform the lookup (the following code in a try/catch block). The
> Tranql resource adapter will take the configuration from the database
> deployment plan and create the database connection pool. And your
> application is portable between different databases with minor changes in
> the database deployment plan and the appropriate resource adapters.
>
> Context initContext = new InitialContext();
> Context envContext = (Context)initContext.lookup("java:/comp/env");
> DataSource ds = (DataSource)envContext.lookup("jdbc/DataSource");
>
> Hope this helps!
> Thanks,
>
> Lin
>
>
> On Feb 9, 2006, at 5:36 AM, Jack Wang wrote:
>
> >
> > Does MySQL5.0.18 suport XA in Tomcat 5.5 ? I do a XA test in tomcat
> > with only a jsp file and
> > necessary jars. The jsp is as:
> >
> > ---------------------------------------------
> > <%
> > Context ctx = new InitialContext();
> > com.mysql.jdbc.jdbc2.optional.MysqlXADataSource xads = new
> > com.mysql.jdbc.jdbc2.optional.MysqlXADataSource();
> > xads.setServerName("localhost");
> > xads.setDatabaseName("test");
> > xads.setPortNumber(3306);
> > XAConnection xcon = xads.getXAConnection("root","password");
> > Connection con = xcon.getConnection();
> >
> > System.out.println("I get the correct xads and the con=" + con);
> > System.out.println("Bind xads to InitialContext");
> >
> > ctx.bind("myXADB", xads);
> > MysqlXADataSource mysqlXADataSource = (MysqlXADataSource)ctx.lookup
> > ("myXADB");
> >
> > System.out.println("Get the null MysqlXADataSource from ctx xads="
> > + mysqlXADataSource );
> > %>
> > ---------------------------------------------
> >
> > Why mysqlXADataSource get from the InitialContext is null ?
> >
> > Is this why I can not configure the XADataSource in tomcat in the
> > previous mail ?
> >
> > I have waste much time in this problem, please help.
> >
> > Thanks.
> >
---------- previous mail begin ---------------
> I hava done a test to use the MySQL XADataSource. For MySQL has no
> MYSQLXADataSourceFactory
> class, so I coded one to produce MysqlXADataSource. MysqlXADataSource is
> configured in tomcat
> 5.5
> server.xml. I can get the MysqlXADataSource instance xaDs by which I can get
> XAConnection and
> XAResource. I also configured a UserTransaction which was produced by
> org.objectweb.jotm.UserTransactionFactory. The following is the action's code
> in a test web
> application. This action runs correctly the first time, but in the second
> time, it runs very
> slow,
> then reports "Lock wait timeout exceeded; try restarting transaction" error.
>
> The first question is that it seems the action did not update the table
> testdata's data. Did
> the
> UserTransaction ut have some error not participate in the database
> transaction?
>
> The second question is that I have searched this error, but don't know how
> to solve it. Please
> give me some tips. Must I not use MySQL's XA in Kandula ? Thanks.
>
>
> The java code (JOTM example):
> ========================================================
> UserTransaction ut = null;
> try{
> Context ctx = new InitialContext();
> MysqlXADataSource xaDs =
> (MysqlXADataSource)ctx.lookup("java:comp/env/jdbc/myXADB");
> ut = (UserTransaction)ctx.lookup("java:comp/env/UserTransaction");
>
> XAConnection xCon = xaDs.getXAConnection();
> java.sql.Connection conn = xCon.getConnection();
>
> System.out.println("<<< beginning the transaction >>> xa con = " + conn);
> ut.begin();
>
> // JDBC statements
> Statement stmt = conn.createStatement();
> ResultSet rst = stmt.executeQuery("select id, foo from testdata");
> if(rst.next()) {
> foo=rst.getInt(2);
> }
> System.out.println("foo = "+ foo +" (before completion)");
>
> String sql = "update testdata set foo=" + (++foo) + " where id=1";
> stmt.executeUpdate(sql);// <=== The program will wait here, and then
> report the error
> message
> !
>
> ut.commit();
> System.out.println("<<< committing the transaction >>>");
>
> conn.close();
> System.out.println("<<< done >>>");
> }catch(Exception e) {
> System.out.print("DBTest >> ");
> e.printStackTrace();
> System.out.println("<<< rolling back the transaction >>>");
> try {
> ut.rollback();
> System.out.println("rollback ok.");
> }catch(Exception e1){
> System.out.println("rollback Error " + e1);
> }
> System.out.println("rollback end");
> }
> }
> ========================================================
>
>
> The error message:
> ========================================================
> ==> xaDataSource = [EMAIL PROTECTED] <==
> <<< beginning the transaction >>> xa con =
> [EMAIL PROTECTED]
> foo = 29 (before completion)
> <<< committing the transaction >>>
> <<< done >>>
> <<< beginning the transaction >>> xa con =
> [EMAIL PROTECTED]
> foo = 29 (before completion)
> - set rollback only (tx=bb14:38:0:01777d30dfc9556034...986c02:)
> DBTest >> java.sql.SQLException: Lock wait timeout exceeded; try restarting
> transaction
> at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2822)
> at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1536)
> at
> com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1159)
> at
> com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:684)
> at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1184)
> at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1101)
> at
> com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1086)
> at
>
com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeUpdate(PreparedStatementWrapper.java:840)
> at foo.XADBTest.init(XADBTest.java:92)
> at
> org.apache.jsp.testJotm_jsp._jspService(org.apache.jsp.testJotm_jsp:55)
> at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
> at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
> at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
> at
>
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
> at
>
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
> at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
> at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
> at java.lang.Thread.run(Thread.java:595)
> <<< rolling back the transaction >>>
> rollback ok.
> rollback end
---------- previous mail end ---------------
___________________________________________________________
雅虎1G免费邮箱百分百防垃圾信
http://cn.mail.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]