On 04/11/2010 07:50, sasidhar prabhakar wrote:
> We are using struts and following DAO pattern.
> 
> This is the code
> 
> 
> public String getCountryName(long ipSum){
>         String name = null;
>        Connection connection = null;
>        PreparedStatement pstmt = null;
>        ResultSet rs = null;
> 
>        try{
>              connection = dataSource.getConnection();
>              pstmt = 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 = pstmt.executeQuery();
>              if( rs.next() ){
>                 name = rs.getString(1);
>              }
> 
>         }catch(Exception ex){
>                ex.printStackTrace();
>         }finally{
>            try{if( rs!=null)rs.close();}catch(SQLException
> ex){ex.printStackTrace();}
>            try {if( pstmt != null)pstmt.close();} catch (SQLException ex)
> {ex.printStackTrace();}
>            try {if( connection != null)connection.close();} catch
> (SQLException ex) {ex.printStackTrace();}
>              connection = null;
>              pstmt = null;
>               rs = null;
>          }
> 
> return name;
> 
> }
> 

Attachment: 0x62590808.asc
Description: application/pgp-keys

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to