Basic question here, can I put String variables into a position in a string array along with more text?
Here’s what I’m trying to do
public static final String CAT_BUD_TAB = "CAT_BUD_TAB";
public static final String inI = "INSERT INTO ";
public static final String val = " VALUES ";
public static final String[] catInsertArray = new String[13];
catInsertArray[0] = inI + CAT_BUD_TAB + val + "(null, 'Student Loan', 'in', 0.00, 0.00, 0.00, 0, 0 );";
But obviously that’s not going to work because it’s expecting ” to mark the start of the string to be contained. Is there anyway this will work?
EDIT
Nope its not the SQL im concerned with, I’m just trying to combine a bit of text with text from a string variable and hold them all as one long string in an array. Might have just made it more confusing, if so ignore this edit and just re-read the original question.
Got rid of the parenthesis as suggested and updated the code block above with all the relevant code.
but eclipse is still saying there’s a “syntax error on tokens, delete these tokens” And has squiggly red lined the whole line of code (catInsertArray[0] = ….)
pastebin of the class here if you’d be good enough to take a look http://pastebin.com/cKa0sKEj
I suspect your original problem was having code that was outside of a method body. This demo class will compile and run, and has comments pointing out what you might have been doing vs. what would be correct.
From your new comment – the code you have in your pastebin link has a few issues. One thing I have is why you are declaring a nested interface inside your
DatabaseConstantsclass? It seems unnecessary since you’re making a class for constants.Additionally, you still leave out a
staticinitializer block to put things into yourStringarray. See the code below.However, for something like a list of constants, I’d prefer to use an enumeration, but hopefully this gets you on the right track to at least getting a working build.