1 Reply Latest reply on Jun 28, 2002 5:05 PM by terry

    LocalStatement Exception attempting to use MySQL specific fu

    terry

      Hi,

      I'm using JBoss 3.0RC3 with a MySQL 3.23.51 database and MM.MySQL JDBC driver 2.0.4. I'm having no problems accessing the database as long as I use a standard JDBC Statement. However, in order to do certain things (namely getting the value for an AUTO_INCREMENT field), you have to cast the Statement to a org.gjt.mm.mysql.Statement. However, when I try to do this, JBoss throws the following exception:

      Exception: org.jboss.resource.adapter.jdbc.local.LocalStatement

      on the following line of code where I attempt to create the connection:

      org.gjt.mm.mysql.Statement stmt = (org.gjt.mm.mysql.Statement)connection.createStatement();

      The connection attribute is defined in a base class and set with a connection factory as shown in the following code snippet:

      static DataSource mysqlDS;
      static final String datasourceName = "java:/MySqlDS";

      static {
      try {
      InitialContext ic = new InitialContext();
      mysqlDS = (DataSource) ic.lookup(datasourceName);

      if( _cat.isInfoEnabled() ) _cat.info("SystemDAOFactory got reference to MySQLDS.");
      } catch (NamingException ne) {
      _cat.error("SystemDAOFactory was not properly intialized. Database access is unavailable.");
      ne.printStackTrace();
      }
      }

      public SystemDAOFactory() {}

      public static Connection getConnection() throws SQLException {

      //return the connection from the datasource
      _cat.info("attempting to create a connection from MySqlDS.");
      if (mysqlDS == null)
      _cat.error("MySqlDS is null.");

      return mysqlDS.getConnection();

      }

      As I said before, this approach works fine on methods where I can use the standard Statement class. I'm curious if anyone has successfully accessed MySQL specific functionality in JBoss 3 and if so, please advise.

      Thanks.

      Terry

        • 1. Re: LocalStatement Exception attempting to use MySQL specifi
          terry

          Follow up to my previous post: I did try upgrading everything. So, I tried it with JBoss 3.0, MySQL 3.23.51 (win32), and MM.MySQL driver 2.0.14. It did produce slightly different results. A class cast exception was thrown at the point where I attempt to cast the Statement instead of a LocalStatement exception:

          java.lang.ClassCastException: org.jboss.resource.adapter.jdbc.local.LocalStatement

          Basically, the same issue. Obviously, I'm trying to do something here that shouldn't be done. Short term hack, I'll load the driver manually and bypass connection pooling for the rare methods where I need the MySQL specific functionality.

          But, if anyone finds this on a search and has a real work-around, please post back. Thanks.

          Terry