-
1. Re: mysql & database pooling
p_d_austin Sep 10, 2001 5:13 PM (in response to neilmcc)With datasources you cannot cast to what you think the prepared statement class is as the application server will generally put a facade in front of the actual preparedstatement, connection and resultset classes. So what you are trying to acheive using the mysql driver's extension to JDBC will not work.
So that was the bad news, the good news is you can get the last id inserted by mysql into and autonumber field using a simple select statement. This is safe across multiple threads as it is tied to the current connection.
idStatement = con.createStatement();
idRs = idStatement.executeQuery("select image_id from nh_image where image_id is null");
if (idRs.next()) {
id = idRs.getLong(1);
}
The key here is that you are selecting the record that the id field is null. -
2. Re: mysql & database pooling
davidjencks Sep 11, 2001 5:25 PM (in response to neilmcc)You can also get the underlying PreparedStatement by calling getUnderlyingPreparedStatement(), and cast that.
-
3. Re: mysql & database pooling
ewlyahoocom Jan 7, 2002 6:13 PM (in response to neilmcc)Use MySQL's "select last_insert_id()"
http://www.mysql.com/doc/M/i/Miscellaneous_functions.html