Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-489

javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.5.9, 1.6.0, 2.0.1
    • 1.6.1, 2.0.2
    • Other
    • None
    • Windows

    Description

      Getting the following stack trace when trying to run XATransactions using Atomikos.

      Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
      at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
      at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
      at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
      at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

      Issue is caused by the XID to String conversion inside MariaXaResource.java

      MariaXaResource.java

          static String xidToString(Xid xid) {
              StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
              sb.append("0x")
                      .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                      .append(",0x")
                      .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                      .append(",").append(xid.getFormatId());
              return sb.toString();
          }
      

      hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

      hexdump should be replaced by implementations like atomikos or mysql connector is using:

      The following code would fix the issue:

      Utils.java

      ....
          protected static String getHex(final byte[] raw) {
              final StringBuilder hex = new StringBuilder(2 * raw.length);
              for (final byte b : raw) {
                  hex.append(hexArray[(b & 0xF0) >> 4])
                          .append(hexArray[(b & 0x0F)]);
              }
              return hex.toString();
          }
          
          public static String byteArrayToHexString(final byte[] bytes) {
              return (bytes != null) ? getHex(bytes) : "";
          }
      

      MariaXaResource.java

      ...
          static String xidToString(Xid xid) {
              StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
              sb.append("0x")
                      .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                      .append(",0x")
                      .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                      .append(",").append(xid.getFormatId());
              return sb.toString();
          }
      ...
      

      Attachments

        Activity

          Tiemo Vorschuetz created issue -
          Tiemo Vorschuetz made changes -
          Field Original Value New Value
          Description Getting the following stack trace when trying to run XATransactions using Atomikos.

          Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
          at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
          at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
          at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
          at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

          Issue is caused by the XID to String conversion inside MariaXaResource.java

              static String xidToString(Xid xid) {
                  StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }

          hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

          hexdump should be replaced by implementations like atomikos or mysql connector is using:

          The following code would fix the issue:

          +Utils.java+:
          ....
              protected static String getHex(final byte[] raw) {
                  final StringBuilder hex = new StringBuilder(2 * raw.length);
                  for (final byte b : raw) {
                      hex.append(hexArray[(b & 0xF0) >> 4])
                              .append(hexArray[(b & 0x0F)]);
                  }
                  return hex.toString();
              }
              
              public static String byteArrayToHexString(final byte[] bytes) {
                  return (bytes != null) ? getHex(bytes) : "";
              }

          +MariaXaResource.java+
          ...
              static String xidToString(Xid xid) {
                  StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          ...
          Getting the following stack trace when trying to run XATransactions using Atomikos.

          Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
          at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
          at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
          at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
          at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

          Issue is caused by the XID to String conversion inside MariaXaResource.java

          {code:title=MariaXaResource.java|borderStyle=solid}
              static String xidToString(Xid xid) {
                  StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          {code}

          hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

          hexdump should be replaced by implementations like atomikos or mysql connector is using:

          The following code would fix the issue:

          {code:title=Utils.java|borderStyle=solid}
          ....
              protected static String getHex(final byte[] raw) {
                  final StringBuilder hex = new StringBuilder(2 * raw.length);
                  for (final byte b : raw) {
                      hex.append(hexArray[(b & 0xF0) >> 4])
                              .append(hexArray[(b & 0x0F)]);
                  }
                  return hex.toString();
              }
              
              public static String byteArrayToHexString(final byte[] bytes) {
                  return (bytes != null) ? getHex(bytes) : "";
              }
          {code}


          {code:title=MariaXaResource.java|borderStyle=solid}
          ...
              static String xidToString(Xid xid) {
                  StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          ...
          {code}
          Tiemo Vorschuetz made changes -
          Description Getting the following stack trace when trying to run XATransactions using Atomikos.

          Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
          at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
          at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
          at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
          at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

          Issue is caused by the XID to String conversion inside MariaXaResource.java

          {code:title=MariaXaResource.java|borderStyle=solid}
              static String xidToString(Xid xid) {
                  StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.*hexdump*(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          {code}

          hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

          hexdump should be replaced by implementations like atomikos or mysql connector is using:

          The following code would fix the issue:

          {code:title=Utils.java|borderStyle=solid}
          ....
              protected static String getHex(final byte[] raw) {
                  final StringBuilder hex = new StringBuilder(2 * raw.length);
                  for (final byte b : raw) {
                      hex.append(hexArray[(b & 0xF0) >> 4])
                              .append(hexArray[(b & 0x0F)]);
                  }
                  return hex.toString();
              }
              
              public static String byteArrayToHexString(final byte[] bytes) {
                  return (bytes != null) ? getHex(bytes) : "";
              }
          {code}


          {code:title=MariaXaResource.java|borderStyle=solid}
          ...
              static String xidToString(Xid xid) {
                  StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          ...
          {code}
          Getting the following stack trace when trying to run XATransactions using Atomikos.

          Caused by: javax.transaction.xa.XAException: (conn:41252) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '0x
          at org.mariadb.jdbc.MariaXaResource.mapXaException(MariaXaResource.java:123)
          at org.mariadb.jdbc.MariaXaResource.execute(MariaXaResource.java:137)
          at org.mariadb.jdbc.MariaXaResource.start(MariaXaResource.java:314)
          at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:297)

          Issue is caused by the XID to String conversion inside MariaXaResource.java

          {code:title=MariaXaResource.java|borderStyle=solid}
              static String xidToString(Xid xid) {
                  StringBuffer sb = new StringBuffer(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.hexdump(Integer.MAX_VALUE, 0, xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          {code}

          hexdump is converting the XID byte arrays into pretty formated string for dumping it to log.

          hexdump should be replaced by implementations like atomikos or mysql connector is using:

          The following code would fix the issue:

          {code:title=Utils.java|borderStyle=solid}
          ....
              protected static String getHex(final byte[] raw) {
                  final StringBuilder hex = new StringBuilder(2 * raw.length);
                  for (final byte b : raw) {
                      hex.append(hexArray[(b & 0xF0) >> 4])
                              .append(hexArray[(b & 0x0F)]);
                  }
                  return hex.toString();
              }
              
              public static String byteArrayToHexString(final byte[] bytes) {
                  return (bytes != null) ? getHex(bytes) : "";
              }
          {code}


          {code:title=MariaXaResource.java|borderStyle=solid}
          ...
              static String xidToString(Xid xid) {
                  StringBuilder sb = new StringBuilder(2 * Xid.MAXBQUALSIZE + 2 * Xid.MAXGTRIDSIZE + 16);
                  sb.append("0x")
                          .append(Utils.byteArrayToHexString(xid.getGlobalTransactionId()))
                          .append(",0x")
                          .append(Utils.byteArrayToHexString(xid.getBranchQualifier()))
                          .append(",").append(xid.getFormatId());
                  return sb.toString();
              }
          ...
          {code}
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.6.1 [ 22550 ]
          Fix Version/s 2.0.2 [ 22551 ]
          diego dupin Diego Dupin added a comment -

          Thanks.
          merge pull request

          diego dupin Diego Dupin added a comment - Thanks. merge pull request
          diego dupin Diego Dupin made changes -
          Component/s Other [ 12201 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 81080 ] MariaDB v4 [ 134993 ]

          People

            diego dupin Diego Dupin
            Tiemo Vorschuetz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.