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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:20:14+00:00 2026-06-15T14:20:14+00:00

How to insert values into a store string value. I have a stored constant

  • 0

How to insert values into a store string value.

I have a stored constant before my method that I will be using for a count variable

Then in my getCount method I have passed in Smith, but it is not getting into the constant when it is called.

public static final String TEST = String.format("SELECT count(first_name) FROM students WHERE last_name = %s",lastName);

    public getCount(String lastName){

        String lastName2 ="";
        lastName2 = lastName;

        count = TEST;

But when I print this out to the screen it says the TEST constant is SELECT count(first_name) FROM students WHERE last_name = lastName" instead of Smith

how can I get this value in here?

  • 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-15T14:20:15+00:00Added an answer on June 15, 2026 at 2:20 pm

    Your constant is only initialized once, (a variable defined as final cannot be changed once it is set) when you first run the program.

    Make it a method instead:

    String getSelectString(String lastName) {
        return String.format("SELECT count(first_name) FROM students WHERE last_name = %s", lastName);
    }
    

    Then you call the method whenever you want to access your “constant”. (Which isn’t really a constant)

    public getCount(String lastName) {
        (...)
        count = getSelectString(lastName);
        (...)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have this method below which should insert values into my database. However
I have to insert values in the table using insert query...the table stored in
I have an application that will, among other things, store various data into a
I'm trying to insert some values into a boost::interprocess::map stored in a shared memory.
my question is how to insert values into DB in sql. i have a
Is there a way that I can insert values into a VB.NET Dictionary when
I am trying to insert certain values into the table using SQL server 2005.
I'd like to be able to insert some values into a table using a
I have a Stored procedure, in which I have to insert 3 strings into
I have been trying to compress and store a json encoded string into mysql,

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.