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?
Your constant is only initialized once, (a variable defined as
finalcannot be changed once it is set) when you first run the program.Make it a method instead:
Then you call the method whenever you want to access your “constant”. (Which isn’t really a constant)