import java.net.URL;
import java.sql.*;

class repro {

   public static void main (String args[]) {
      String url = "jdbc:mariadb://lnxx64r7:3307/db999_lnxpleu14" ;
      Connection con = null;
      DatabaseMetaData dma = null; 

      System.out.println("\n\n"); 
      System.out.println("BUG SYNOPSIS: getTables call fails w/ syntax error");
      System.out.println("Failure occurs when using MariaDB JDBC driver V1.5.2 ");
      System.out.println(", but works when using MariaDB JDBC driver V1.4.6 ");
      System.out.println("");                              

      try {

         // Load the MariaDB jdbc driver

         Class.forName ("org.mariadb.jdbc.Driver");

//       DriverManager.setLogStream(System.out);
   
         // Attempt to connect to a driver.  Each one
         // of the registered drivers will be loaded until
         // one is found that can process this URL

         DriverManager.setLoginTimeout(15);

         con = DriverManager.getConnection (
            url, "R729999D", "edaport");

         // If we were unable to connect, an exception
         // would have been thrown.  So, if we get here,
         // we are successfully connected to the URL

         // Check for, and display and warnings generated
         // by the connect.

         checkForWarning (con.getWarnings ());

         // Get the DatabaseMetaData object and display
         // some information about the connection

         dma = con.getMetaData ();

         System.out.println("\nConnected to " + dma.getURL());
         System.out.println("Driver       " + 
         dma.getDriverName());
         System.out.println("Version      " +
         dma.getDriverVersion());
         System.out.println("");
      }

      catch (SQLException ex) {

         // A SQLException was generated.  Catch it and
         // display the error information.  Note that there
         // could be multiple error objects chained
         // together

         System.out.println ("\n*** SQLException caught ***\n");

         while (ex != null) {
            System.out.println ("SQLState: " +
               ex.getSQLState ());
            System.out.println ("Message:  " + ex.getMessage ());
            System.out.println ("Vendor:   " +
               ex.getErrorCode ());
            ex = ex.getNextException ();
            System.out.println ("");
         }
         return;
      }

      catch (java.lang.Exception ex) {

         // Got some other type of exception.  Dump it.
         ex.printStackTrace ();
         return;
      }


      try {


        
         System.out.println("\ncall getTables() ");
         dma.getTables(null, null, "junk", null);
         System.out.println("\nIF WE GOT HERE, WE DID NOT REPRO THE BUG!");
         // Close the connection

         con.close();
      }

      catch (SQLException ex) {
         // A SQLException was generated.  Catch it and
         // display the error information.  Note that there
         // could be multiple error objects chained
         // together

         System.out.println ("\n*** SQLException caught ***\n");

         while (ex != null) {
            System.out.println ("SQLState: " +
               ex.getSQLState ());
            System.out.println ("Message:  " + ex.getMessage ());
            System.out.println ("Vendor:   " +
               ex.getErrorCode ());
            ex = ex.getNextException ();
            System.out.println ("");

         }
      }
       catch (java.lang.Exception ex) {
   
           // Got some other type of exception.  Dump it.

           ex.printStackTrace ();
       }
   } // end of main


   //-------------------------------------------------------------------
   // checkForWarning
   // Checks for and displays warnings.  Returns true if a warning
   // existed
   //-------------------------------------------------------------------

   private static boolean checkForWarning (SQLWarning warn) 
      throws SQLException  {
      boolean rc = false;

      // If a SQLWarning object was given, display the
      // warning messages.  Note that there could be
      // multiple warnings chained together

      if (warn != null) {
         System.out.println ("\n *** Warning ***\n");
         rc = true;
         while (warn != null) {
            System.out.println ("SQLState: " +
               warn.getSQLState ());
            System.out.println ("Message:  " +
               warn.getMessage ());
            System.out.println ("Vendor:   " +
               warn.getErrorCode ());
            System.out.println ("");
               warn = warn.getNextWarning ();
         }
      }
      return rc;
   }
}
