Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4028240
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:11:47+00:00 2026-05-20T11:11:47+00:00

I am trying to execute a parameter query for a Postgre database using Springs

  • 0

I am trying to execute a parameter query for a Postgre database using Springs SimpleJdbcTemplate. My class that calls the query looks like this:

public class GeoCodeServiceImpl extends SimpleJdbcDaoSupport implements GeoCodeServiceInterface {

public static final String SELECT_STATEMENT = "SELECT ste_code, ste_code_type, name, fips_code " +
                                              "FROM \"steGeo\" " +
                                              "WHERE st_contains( the_geom, ST_GeomFromText('POINT(:lon :lat)',4269))";

public List<GeoCode> getGeoResults(Double lon, Double lat) throws DataAccessException {

    MapSqlParameterSource mappedParms = new MapSqlParameterSource("lon", lon.toString());
    mappedParms.addValue("lat", lat.toString());
    SqlParameterSource namedParms = mappedParms;

    List<GeoCode> resultList = getSimpleJdbcTemplate().query(SELECT_STATEMENT, new GeoCodeRowMapper(), namedParms);

    if (resultList == null || resultList.size() == 0) {
        logger.warn("No record found in GeoCode lookup.");
    }

    return resultList;

}

protected static final class GeoCodeRowMapper implements RowMapper<GeoCode> {
    public GeoCode mapRow(ResultSet rs, int i) throws SQLException {
        GeoCode gc = new GeoCode();
            gc.setCode(rs.getString(1));
            gc.setType(rs.getString(2));
            gc.setFips(rs.getString(3));
            gc.setName(rs.getString(4));
        return gc;
    }
}

}

I am testing the query with this class:

public class GeoCodeServiceTest {

public static void main(String[] args) {

    Double lat = 40.77599;
    Double lon = -83.82322;

    String[] cntxs = {"project-datasource-test.xml","locationService-context.xml"};
    ApplicationContext ctx = new ClassPathXmlApplicationContext(cntxs);
    GeoCodeServiceImpl impl = ctx.getBean("geoCodeService", GeoCodeServiceImpl.class);
    List<GeoCode> geoCodes = impl.getGeoResults(lon, lat);
    System.out.println(geoCodes);
}

}

I keep getting the following error:

    2011-03-07 08:16:29,227 [main] DEBUG org.springframework.jdbc.support.SQLErrorCodesFactory - SQL error codes for 'PostgreSQL' found
2011-03-07 08:16:29,227 [main] DEBUG org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - Unable to translate SQLException with SQL state 'XX000', error code '0, will now try the fallback translator
2011-03-07 08:16:29,227 [main] DEBUG org.springframework.jdbc.support.SQLStateSQLExceptionTranslator - Extracted SQL state class 'XX' from value 'XX000'
Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT ste_code, ste_code_type, name, fips_code FROM "steGeo" WHERE st_contains( the_geom, ST_GeomFromText('POINT(:lon :lat)',4269))]; SQL state [XX000]; error code [0]; ERROR: parse error - invalid geometry
  Hint: "POINT(" <-- parse error at position 6 within geometry; nested exception is org.postgresql.util.PSQLException: ERROR: parse error - invalid geometry
  Hint: "POINT(" <-- parse error at position 6 within geometry

It looks like my parameters are not populated.
I haven’t used Postgre before so any help would be much appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:11:47+00:00Added an answer on May 20, 2026 at 11:11 am

    Parameters are not handled inside quoted strings, so I guess you need to pass the whole string as a single parameter:

    public static final String SELECT_STATEMENT = 
        "SELECT ste_code, ste_code_type, name, fips_code " +
        "FROM \"steGeo\" " + 
        "WHERE st_contains( the_geom, ST_GeomFromText(:pt, 4269))"; 
    
    ...
    MapSqlParameterSource mappedParms = new MapSqlParameterSource("pt", 
        "POINT(" + lon.toString() + " " + lat.toString() + ")");   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute a query like this: SELECT * FROM table WHERE id
I have a stored procedure that I'm trying to execute using Dapper that is
I'm trying to execute a query in PostgreSQL using the following code. It's written
I am trying to implement the Like operator by using the entity framework query.
I'm having trouble getting this simple query to execute. I'm using nameless parametized queries
I'm trying to execute this SQL command in the VS Query Builder: INSERT INTO
I have the following query that I am trying to execute. It is the
I'm trying to execute an E4X query (on the xml below) that will return
I am trying to execute an INSERT INTO query using .Net through the MySql/.NEt
I'm trying to execute a query that currently works in phpMyAdmin but it does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.