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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.9, 1.6.0, 2.0.1
    • Fix Version/s: 1.6.1, 2.0.2
    • Component/s: Other
    • Labels:
      None
    • Environment:
      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

            People

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

              Dates

              Created:
              Updated:
              Resolved: