You might have to dig into the mm.mysql and jdbc drivers and change the
cast appropriately.

Heres a snippet of code that I used:
                        // Non-portable code follows. Only works with jboss and mysql.
                        // be sure to add jbosspool.jar and mm-mysql2.0.jar to your 
classpath!!
                        // Now uses some trickery to get the last autoincrement id 
generated by
mysql
                        // to do this we need to access methods on mysql's 
implementation of
statement
                        // first, cast stmt to a jboss statement. Then get the 
underlying
statement and
                        // cast it to a mysql statement. Then calll getLastInsertID to 
get the
last autogenerated
                        // id.
                        if (L.ON) log.debug("stmt.class="+stmt.getClass());

                        if (stmt instanceof org.gjt.mm.mysql.jdbc2.PreparedStatement) {

retValue=(int)((org.gjt.mm.mysql.jdbc2.PreparedStatement)stmt).getLastInsert
ID();
                        } else {
                                org.jboss.pool.jdbc.StatementInPool jbossStmt=
                                        (org.jboss.pool.jdbc.StatementInPool)stmt;
                                org.gjt.mm.mysql.jdbc2.PreparedStatement mysqlStmt=

(org.gjt.mm.mysql.jdbc2.PreparedStatement)jbossStmt.getUnderlyingStatement();
                                retValue=(int)mysqlStmt.getLastInsertID();
                        }


Regards, John

At 02:55 PM 8/13/2002 +0200, you wrote:
>I have a application where I use the statement :
>
>last_id = ((org.gjt.mm.mysql.Statement) pstmt).getLastInsertID();
>
>with struts 1.1b1 and mm.mysql driver (most recent) it works good. But
>now I have upgraded to a newer version of struts (and mysql) and it
>stopped working. I get the following error :
>
>java.lang.ClassCastException:
>org.apache.commons.dbcp.DelegatingPreparedStatement
>       at
>nl.linuxonline.shop.product.PictureJdbcBean.insert(PictureJdbcBean.java:
>67)
>       at
>nl.linuxonline.shop.product.CreatePictureAction.execute(CreatePictureAct
>ion.java:100)
>       at
>org.apache.struts.action.RequestProcessor.processActionPerform(RequestPr
>ocessor.java:446)
>.....
>
>I replaced the code with a max(id) and now it works again, but does
>anybody know why this doesn't work anymore ??
>
>Or is there a better way to use autoincrement ??
>
>Regards,
>
>Edwin
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to