With a UNION clause you only get one column back. You probably want to select both columns rather than do a UNION since they are coming from the same table. Why are doing a UNION?
You may want to code your select this way:
I guess it depends on your database. I am using Oracle and your SQLs do not produce identical results in Oracle.
Your original SQL used double-quotes, but this does not work in Oracle and gives a syntax error, so I changed it to single-quote:
Your SQL will produce two columns, but it goes back to my original point that it was a SQL issue and the original poster was using the incorrect SQL. If he uses your SQL, that should fix his problem, but then he has to be aware that some admin and user2 variables will have blank values as the above SQL illustrates. Is this what the original poster wants? If no, then a simple SQL will do the job rather than a UNION:
The original poster should illustrate with example data of what is in the table 'private' and what he want to populate his objects with?
in case of Original poster's original query of union the resultset what we get is of single column named as admin as select admin from private is the first query and there is no column named user2 thats why he was not getting that column in temp1.setMem2(rs.getString("user2"));
George W Smith wrote:No its the correct one alright as when I execute a query on just the select user2 with no union it works fine.
Is their a problem with unions and jdbc or am I making a mistake in it somewhere?
if you using mysql than read my post but check it in your complex statement it work not for just example.
Remember that when you try to union of two sql than both or more sql which you want to join have same column name so you use blank if necessary
also remember that use single quote if you use oracle. and in mysql both quotes are valid.