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

  • Home
  • SEARCH
  • 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 8023639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:37:09+00:00 2026-06-04T22:37:09+00:00

The typical situation: we have some nullable column with type Integer and it might

  • 0

The typical situation: we have some nullable column with type Integer and it might be both null or some int value. So we use the following:

private static void setIntOrNull(PreparedStatement stmt, int col, Integer i)
    throws SQLException
    {
        if (i == null)
            stmt.setNull(col, java.sql.Types.INTEGER);
        else
            stmt.setInt(col, i);
    }

But for me this case is kind of bad practise – to change the external object within internal void method (reffering to Robert Martin’s “Clean Code” Chapter 17: Smells and Heuristics, Functions, F2). I try to avoid such situation, but this time I just could not find a better solution. Maybe someone could help me with one?

  • 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-06-04T22:37:10+00:00Added an answer on June 4, 2026 at 10:37 pm

    I don’t think it’s particularly bad, really. Let’s see:

    • It’s void, so it must have side-effects, or be useless
    • It’s static, so it can’t have any effect on “the object it’s called” on; there isn’t one!

    So either the side-effect is going to be a global one (e.g. external such as a file system, internal such as static variable, or temporal e.g. sleeping) or it will affect one of the objects referred to by the parameters.

    The int isn’t an object, Integer objects are immutable, so the only thing it can be affecting is the PreparedStatement. As one of the purposes of prepared statements is to collect parameter data, it seems entirely reasonable that the method will do so. The method name makes this even clearer – where else is it going to “set” an int or null, if not on the prepared statement?

    Basically: don’t worry 🙂

    You may want to make this even clearer by moving it to a public “helper” class such as PreparedStatementHelper – that makes it potentially obvious that really you’d like these methods to be on PreparedStatement, but they’re not so you’ve got to have a static method instead to act on a PreparedStatement.

    One alternative would be to create your own wrapper class which would maintain a PreparedStatement itself, and have an instance setIntOrNull method… but in the long run I believe that would be a lot more complicated, for little benefit.

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

Sidebar

Related Questions

I have a typical situation. my table has four column. (id, user, col2, status)
I have a typical definition/instance situation in my data modeling. I'm trying to store
A typical situation: In my GridView control, I have a Footer row which contains
I have a situation where I need to unit test some scenarios that require
I have typical situation where big loop is loading lots of images and its
I have a dilemma, and I could really use some advice. I am building
I have a typical Flex-based application that was written to use a Java/Hibernate/MySQL backend.
I have a very typical situation. We have a table called Users which has
current situation: I have a service with several typical service methods like create(), remove(),
I have a Java RMI system. The situation is typical: the client invokes a

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.