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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:47:35+00:00 2026-06-13T08:47:35+00:00

I have a problem with useing NULL as Integer parameter. I have 3 classes

  • 0

I have a problem with useing NULL as Integer parameter.

I have 3 classes which extend each other:

//1st
public class StandardTableIntId {
    ...

    protected MethodAnswer changeField(String field, Integer value) {
    DBConnection dbc = new DBConnection();
    Connection con = dbc.getConnection();
    try {
        PreparedStatement st = con.prepareStatement("UPDATE " + this.tableName + " SET " + field + " = ? WHERE id = ?");
        st.setInt(1, value);
        st.setInt(2, this.id);
        st.executeUpdate();
        return MethodAnswer.OK;
    } catch (SQLException ex) {
        log.info("SQLException. Class: StandardTableIntId. Method: changeField(String field, String value). Parameters: table='" + tableName + "' id='" + id + "' field='" + field + "' value='" + value + "'");
        return MethodAnswer.DB_EXCEPTION;
    }
    finally
    {
        dbc.closeConnection();
    }   
    }
    protected MethodAnswer changeField(String field, String value) {
    ...
    st.setString(1, value);
    ...}
    protected MethodAnswer changeField(String field, Long value) {
    ...
    st.setLong(1, value);
    ...}
    protected MethodAnswer changeField(String field, boolean value) {
    ...
    st.setBoolean(1, value);
    ...}
    ...
}   


//2nd
public class StandardTableIntIdTimed extends StandardTableIntId{...}

//3rd   
public class Company extends StandardTableIntIdTimed {
    ...
    public MethodAnswer setMainIncomeBankAccountId(Integer value) {
        MethodAnswer ans;
// !!! Code crashes in next command (if value==null). Eclipse just said: "Source not found." in debugging mode.
            ans = changeField("mainIncomeBaId", value); 
        return ans;
    }
    ...
}

Code crashes in line that marked “//!!!” comment. It happens when “value” is equals to null.

In the same methods but String or Timestamp params is everithing OK:

public MethodAnswer setPostAddress(String postAddress) {
    MethodAnswer ans;
    ans = changeField("postAddress", value); 
    return ans;
}
public MethodAnswer setDateTimeBegin(Timestamp value) {
    MethodAnswer ans;
    ans = changeField("DateTimeBegin", value); 
    return ans;
}

Can’t understend what’s happening here and how to fix it.

  • 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-13T08:47:36+00:00Added an answer on June 13, 2026 at 8:47 am

    Ok, I’m guessing a bit here, but…

    protected MethodAnswer changeField(String field, Integer value)
    

    If you within this method convert the value parameter to an int, and value is NULL, then you will get a NullPointerException. The solution: Check if value is NULL before converting it to int.

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

Sidebar

Related Questions

I have a strange problem. I am using the null layout for a window
I have a database table which contains an unsigned integer field to store the
I have a problem setting null to a variant field using rtti. Suppose I
I have two tables: CREATE TABLE items ( root_id integer NOT NULL, id serial
I'm using app engine datastore so I have entity like this. @PersistenceCapable public class
I have an JPA entity like this: @Entity @Table(name = category) public class Category
I have problem using arabic font for iOS. All fonts have the same render,
i have problem using LIKE structure in DB2 : for example: select * from
I have problem while using jquery maskedinput with asp.net textbox. I have a check
I have a problem using a local SQL Server CE database with C# and

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.