You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-user@db.apache.org by Robert Einsle <ro...@einsle.de> on 2005/10/28 14:57:14 UTC
Closing Database while retriving the Platform
Hy,
an aditional Question. When i retrive the Platform (Platform platform =
PlatformFactory.createNewPlatformInstance(<Datasource));) DdlUtils
closes the java.sql.Connection inside the Datasource. Is it possible to
let DdlUtils not close the Conenction?
So i have to create an Connection, let create the Platform, the create
the Connection again.
Thanks for Help.
\Robert
Re: Closing Database while retriving the Platform
Posted by Robert Einsle <ro...@einsle.de>.
Hy,
Thomas Dudziak schrieb:
>On 10/28/05, Robert Einsle <ro...@einsle.de> wrote:
>
>
>
>>an aditional Question. When i retrive the Platform (Platform platform =
>>PlatformFactory.createNewPlatformInstance(<Datasource));) DdlUtils
>>closes the java.sql.Connection inside the Datasource. Is it possible to
>>let DdlUtils not close the Conenction?
>>
>>
>
>Sorry, no, because that is the recommended way of working with
>datasources and connections.
>
>
Ah, oki, thats n argument.
>
>
>>So i have to create an Connection, let create the Platform, the create
>>the Connection again.
>>
>>
>
>You should hold onto connections only as long as you need them, not
>longer. If you have performance issues because of frequent connection
>creation, consider using a pooled data source (almost every jdbc
>driver comes with such an implementation). These data sources keep the
>connections open internally (the call to close on the connection then
>does not really close the connection but rather returns it to the
>pool).
>
>
Thanks for this Idea. I'll look at this today.
>Tom
>
>
>
\Robert
Re: Closing Database while retriving the Platform
Posted by Thomas Dudziak <to...@gmail.com>.
On 10/28/05, Robert Einsle <ro...@einsle.de> wrote:
> an aditional Question. When i retrive the Platform (Platform platform =
> PlatformFactory.createNewPlatformInstance(<Datasource));) DdlUtils
> closes the java.sql.Connection inside the Datasource. Is it possible to
> let DdlUtils not close the Conenction?
Sorry, no, because that is the recommended way of working with
datasources and connections.
> So i have to create an Connection, let create the Platform, the create
> the Connection again.
You should hold onto connections only as long as you need them, not
longer. If you have performance issues because of frequent connection
creation, consider using a pooled data source (almost every jdbc
driver comes with such an implementation). These data sources keep the
connections open internally (the call to close on the connection then
does not really close the connection but rather returns it to the
pool).
Tom
Re: Closing Database while retriving the Platform
Posted by Robert Einsle <ro...@einsle.de>.
Hy
here is the matching Code-Sniplet from PlatformUtils:
--- cut ---
/**
* Tries to determine the database type for the given data source.
Note that this will establish
* a connection to the database.
*
* @param dataSource The data source
* @return The database type or <code>null</code> if the database
type couldn't be determined
*/
public String determineDatabaseType(DataSource dataSource) throws
DynaSqlException
{
Connection connection = null;
try
{
connection = dataSource.getConnection();
DatabaseMetaData metaData = connection.getMetaData();
return determineDatabaseType(metaData.getDriverName(),
metaData.getURL());
}
catch (SQLException ex)
{
throw new DynaSqlException("Error while reading the database
metadata", ex);
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch (SQLException ex)
{
// we ignore this one
}
}
}
}
--- cut ---
Robert Einsle schrieb:
> Hy,
>
> an aditional Question. When i retrive the Platform (Platform platform
> = PlatformFactory.createNewPlatformInstance(<Datasource));) DdlUtils
> closes the java.sql.Connection inside the Datasource. Is it possible
> to let DdlUtils not close the Conenction?
>
> So i have to create an Connection, let create the Platform, the create
> the Connection again.
>
> Thanks for Help.
>
> \Robert
>
\Robert