tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pid <...@pidster.com>
Subject Re: DBCP abandoned trace - unable to understand the leak
Date Wed, 10 Nov 2010 08:56:35 GMT
On 04/11/2010 07:50, sasidhar prabhakar wrote:
> We are using struts and following DAO pattern.
>=20
> This is the code
>=20
>=20
> public String getCountryName(long ipSum){
>         String name =3D null;
>        Connection connection =3D null;
>        PreparedStatement pstmt =3D null;
>        ResultSet rs =3D null;
>=20
>        try{
>              connection =3D dataSource.getConnection();
>              pstmt =3D connection.prepareStatement("select country_name=
 from
> ip_to_geo where ? between ip_from and ip_to");

That query looks like a candidate for being slow to me.

>              pstmt.setString(1, ""+ipSum);

Minor: but pstmt.setString(1, String.valueOf(ipSum)) would be better.

Slightly less minor, is the question, why are you converting a long to a
string and then attempting to conduct a range operation on it?

There's another method: pstmt.setLong(1, ipSum) which might work, unless
your DB tables are strangely constructed.


p

>              rs =3D pstmt.executeQuery();
>              if( rs.next() ){
>                 name =3D rs.getString(1);
>              }
>=20
>         }catch(Exception ex){
>                ex.printStackTrace();
>         }finally{
>            try{if( rs!=3Dnull)rs.close();}catch(SQLException
> ex){ex.printStackTrace();}
>            try {if( pstmt !=3D null)pstmt.close();} catch (SQLException=
 ex)
> {ex.printStackTrace();}
>            try {if( connection !=3D null)connection.close();} catch
> (SQLException ex) {ex.printStackTrace();}
>              connection =3D null;
>              pstmt =3D null;
>               rs =3D null;
>          }
>=20
> return name;
>=20
> }
>=20


Mime
View raw message