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 6847933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:48:19+00:00 2026-05-27T00:48:19+00:00

In my project I use Spring 3.0 JdbcTemplate to implement DAO classes. It provides

  • 0

In my project I use Spring 3.0 JdbcTemplate to implement DAO classes. It provides convenient methods like query(…), update(…) etc. These methods accept objects as arguments to bind to the query. In javadoc it is stated that it is left to the PreparedStatement to guess the corresponding SQL type. So when using primitives or wrappers it is simple.

But in my code I use special classes for id representation. For example UserId. It has public method to get its integer value – getInt(). Right now I have to use

userId.getInt()

every time I need to pass instance of UserId to the JdbcTemplate query. If I forget and write just

userId

I obviously get SQLException, as my UserId object can’t be consumed by prepared statement (here are the rules to map Object type to corresponding SQL type). But this type of error can’t be spotted during compilation (as JdbcTemplate accepts Object as parameter), which makes bugs introducing easy.

Is there any way I can avoid calling .getInt() and just pass my UserId object into the query?

  • 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-27T00:48:20+00:00Added an answer on May 27, 2026 at 12:48 am

    I imagine you could override org.springframework.jdbc.core.JdbcTemplate.newArgPreparedStatementSetter(Object[]) with a new version of org.springframework.jdbc.core.ArgPreparedStatementSetter that checks (in doSetValue) whether the Object argValue is of your special UserId type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use spring support for sending mails. My project is built with
For a new project, we've decided to use Spring MVC, and JdbcTemplate (specifically SimpleJdbcTemplate)
I have a Spring Roo project and I use mvn jetty:run to run my
My Java (JDK6) project uses Spring and JDBCTemplate for all its database access. We
I am developing a GWT-Spring-Hibernate project and I want to use Spring Autowired annotation
good people. i'm trying to use quartz with spring in a very simple project
I'm just starting a project and decided to use Spring with Appengine. I'm now
I am working on a spring project. I use ant to deploy application and
In our C# project we use Spring as an Inversion of Control (IoC) container.
I have the need to use Spring .Net in a project and am exploring

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.