Mariadb java client does not support useServerPrepStmts

  • Epic Name:

    Use server prepareStatement
  • Sprint:

    Sprint connector/j 1.3.0

To enable prepared statements on the server side, MySQL Connector/J provides useServerPrepStmts parameter.
It doesn’t work for MariaDB client. If there is a way to get prepared statements work through MariaDB client, I haven’t yet found it.

The provided test case checks the global value of Prepared_stmt_count status variable, then attempts to prepare a statement on a connection with useServerPrepStmts, then checks the variable value again.

Output with MariaDB client library 1.1.0:

Prepared_stmt_count before prepare: 0
Prepared_stmt_count after prepare: 0

With MySQL Connector/J 5.1.23:

Prepared_stmt_count before prepare: 0
Prepared_stmt_count after prepare: 1

exmaples

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;


public class BugPreparedStatement
{
  public static void main (String argv[])  
  {
    try {

      Statement status = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","").createStatement();

      ResultSet rs = status.executeQuery("show global status like 'Prepared_stmt_count'");
      if (rs.first()) {
        System.out.println("Prepared_stmt_count before prepare: " + rs.getInt(2));  
      }

      PreparedStatement pst = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useServerPrepStmts=true","root","").prepareStatement("select 1");

      rs = status.executeQuery("show global status like 'Prepared_stmt_count'");
      if (rs.first()) {
        System.out.println("Prepared_stmt_count after prepare: " + rs.getInt(2));  
      }
    }
    catch (Exception e)
    {
      System.out.println("Exception: " + e + "\n");
      e.printStackTrace();
    }
  } 
}

Refered From : https://mariadb.atlassian.net/browse/CONJ-22

 

Leave a Reply

Your email address will not be published. Required fields are marked *