Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
10.4.2.0
-
None
-
Regression
Description
Got below error message when running an XA prolgram with derby.
org.apache.derby.client.am.XaException: XAER_PROTO : Error executing a XAResource.start(), server returned XAER_PROTO.
at org.apache.derby.client.net.NetXAResource.throwXAException(Unknown Source)
at org.apache.derby.client.net.NetXAResource.start(Unknown Source)
at TestDerbyXA.process(TestDerbyXA.java:186)
at TestDerbyXA.main(TestDerbyXA.java:43)
Caused by: org.apache.derby.client.am.SqlException: Error executing a XAResource.start(), server returned XAER_PROTO.
at org.apache.derby.client.net.NetXAResource.xaRetValErrorAccumSQL(Unknown Source)
... 3 more
Below is the example program I used. Note: The program will succeed if comment out line 147 - setTransactionTimeout. Does that means call XAResource.setTransactionTimeout() caused the failure?
I use Apache Derby Network Server - 10.4.2.0 - (689064). The same program works fine with another version Apache Derby Network Server - 10.2.2.0 - (485682). It looks like there is a regression between the two versions.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.XAConnection;
import javax.transaction.xa.XAException;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import org.apache.derby.jdbc.ClientXADataSource;
public class TestDerbyXA {
ClientXADataSource xaDSLocal = null;
ClientXADataSource xaDSRemote = null;
public TestDerbyXA()
{ // Create two XA data sources. xaDSLocal = new ClientXADataSource(); xaDSLocal.setServerName("localhost"); xaDSLocal.setPortNumber(1527); xaDSLocal.setDatabaseName("testdb"); xaDSLocal.setUser("app"); xaDSLocal.setPassword("derby"); xaDSRemote = new ClientXADataSource(); xaDSRemote.setServerName("localhost"); xaDSRemote.setPortNumber(1527); xaDSRemote.setDatabaseName("testdb"); xaDSRemote.setUser("app"); xaDSRemote.setPassword("derby"); // xaDSRemote = xaDSLocal; }public static void main(String[] args) throws Exception
{ TestDerbyXA testObj = new TestDerbyXA(); testObj.dropTable("tablea"); testObj.createTable("CREATE TABLE tablea (col1 INT, col2 VARCHAR(32))"); testObj.dropTable("tableb"); testObj.createTable("CREATE TABLE tableb (col1 INT, col2 VARCHAR(32))"); testObj.process(); } public void dropTable(String tableName) throws Exception {
Connection conn = null;
Statement stmt = null;
try
{ conn = xaDSLocal.getConnection(); stmt = conn.createStatement(); stmt.executeUpdate("DROP TABLE " + tableName); System.out.println("Drop table " + tableName + " succeed."); }catch (SQLException sqle)
{ System.out.println("Drop table " + tableName + " failed."); sqle.printStackTrace(); } finally {
// ============ Close JDBC objects, including the connection =======
if (stmt != null) {
try
}
}
if (conn != null) {
try { conn.close(); conn = null; } catch (SQLException e) {
}
}
}
}
public void createTable(String DDL) throws Exception {
Connection conn = null;
Statement stmt = null;
try { conn = xaDSLocal.getConnection(); stmt = conn.createStatement(); stmt.executeUpdate(DDL); System.out.println(DDL + " succeed."); } catch (SQLException sqle) { System.out.println(DDL + " failed."); sqle.printStackTrace(); } finally {
// ============ Close JDBC objects, including the connection =======
if (stmt != null) {
try { stmt.close(); stmt = null; }
catch (SQLException e) {
}
}
if (conn != null) {
try
catch (SQLException e) {
}
}
}
}
public void process() throws Exception {
Connection connLocal = null;
Connection connRemote = null;
int rows = 0;
PreparedStatement pstmtLocal = null;
PreparedStatement pstmtRemote = null;
XAConnection xaConnLocal = null;
XAConnection xaConnRemote = null;
XAResource xarLocal = null;
XAResource xarRemote = null;
Xid xidLocal = null;
Xid xidRemote = null;
try
catch (SQLException e)
{ System.err.println("SQL Error: " + e.getMessage()); e.printStackTrace(); }catch (XAException e)
{ System.err.println("XA Error: " + e.getMessage()); e.printStackTrace(); } finally {
if (pstmtLocal != null)
try
catch (SQLException ignore) {
}
if (pstmtRemote != null)
try
catch (SQLException ignore) {
}
if (connLocal != null)
try
catch (SQLException ignore) {
}
if (connRemote != null)
try
catch (SQLException ignore) {
}
if (xaConnLocal != null)
try
catch (SQLException ignore) {
}
if (xaConnRemote != null)
try
catch (SQLException ignore) {
}
}
}
}