ResultSet rs = stmt.executeQuery= ("
SELECT COLUMN1 as STRING WITH SPACE ex EMPLOYEE NAME
FROM TABLE1
WHERE CONDITION1 = CONDITION
");
If I were to use an alias with no space it would work, but in this case I need an alias with the spaces between the words. How do I do that when the entire SQL statement is in a string?
The typical way to do this is to use an escape character. In other words, you tell the compiler that what follows is actually part of the string, not the end of the string itself. So for example, entering "She told me "I didn't hear you" to my face."
would get compiled as "She told me "
plus the nonsense I didn't hear you
plus the final string " to my face."
With escape characters, you would write it as something like "She told me ""I didn't hear you"" to my face."
In this case it is a double quote, but it depends on what compiler you are talking to. Try something like this:
ResultSet rs = stmt.executeQuery= ("
SELECT COLUMN1 as ""STRING WITH SPACE"" ex EMPLOYEE NAME
FROM TABLE1
WHERE CONDITION1 = CONDITION
");
Really though, I recommend you just use underscores or no spaces. In my experience, everything is harder on you and everyone else who works on it after you when you have to fight your column aliases.