-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Randy wrote:

> Hello,
>
> I need a little help
>
> Hopefully I can give the info needed.
>
> My servlets have been using this code I found a long time ago called
> "DbConnectionBroker"
>
> It works very well.
>
> I have been trying to move to the db connection pool of tomcat.
>
> They both use org.gjt.mm.mysql.Driver
>
> But here is where I am having problems. Hopefully this little piece of
code
> is enough to help
>
> The thing that is different is the connection I get from the
> DbConnectionBroker is different that the one I get from
>
> /////
> //this is what I do to use jndi
>  ds = (DataSource)ctx.lookup(JNDICONTEXTLOOKUP);
>  conn = ds.getConnection();
> /////
>
> So I guess my question is, is someone using JNDI with mysql and
getting the
> LastInsertID..
>
> When I use the connection broker this piece of code below works fine, but
> when I use it with jndi the line long newKey =
> ((org.gjt.mm.mysql.Statement)stmt).getLastInsertID() ;
> Gets a class cast exception
>
>
> Thanks for any help.......
>
>
> try{
>           Statement stmt = conn.createStatement();
>           int ret = stmt.executeUpdate(ustr);
>           rowsProcessed = ret;
>           if ( ret == 0 ){
>                   writeErrorInfo(userID,"executeSql",
>                                        "executeSql Failed - non fatal
> error , no rows processed",
>                                        "no rows processed",-1);
>                   stmt.close();
>                   return -1;
>           }
>           long newKey =
((org.gjt.mm.mysql.Statement)stmt).getLastInsertID()
> ;
>           stmt.close();
>           return (int)newKey;
> }catch (SQLException e){

Use MySQL's Connector/J 3.x or 3.1.x (they're what MM.MySQL 'grew up'
to), and use the JDBC-standard Statement.getGeneratedKeys() method to do
the same thing.

        -Mark


- --
Mr. Mark Matthews
MySQL AB, Software Development Manager, J2EE and Windows Platforms
Office: +1 708 332 0507
www.mysql.com

MySQL Guide to Lower TCO
http://www.mysql.com/it-resources/white-papers/tco.php
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFA0LlftvXNTca6JD8RAu/YAKCNXcgLQE/mkow0PvrKy/hwFLp+2gCgqhXy
dpr37EvR/tnOfcIvGmWWIic=
=stm+
-----END PGP SIGNATURE-----

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

Reply via email to