George W Smith

Greenhorn
+ Follow
since Apr 29, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by George W Smith

Yes I know that, the long complex statement wasnt working. Therefore I am attempting to get a simpler one working with two basic selects.
Both statements give the same error.
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?
String statement = "SELECT admin from private union SELECT user2 from private";
prep = conn.prepareStatement(statement);
ResultSet rs = (ResultSet) prep.executeQuery();
while(rs.next()) {
temp1.setAdmin(rs.getString("admin"));
temp1.setMem2(rs.getString("user2"));
leagues.add(temp1);
}
conn.close();

Error:

Column 'user2' not found

The error is when I run it and it says no data to display.
There is a column user2 in the private table in the sql database, as the full statement works at command line.
Hi All,

I am trying to use a union to get data in a table in my java class. In the mysql database the query executes perfectly.
However when ran in the java class it says it cannot find "user2"?

I have simplified the statement to the extreme(!!!) and it still says the same? Code is below any help would be great.

SELECT admin from private union SELECT user2 from private;

(user2 is a column in the database...)