我有兩個表與我,網絡和郵件。目前我正在使用此查詢從兩個表中獲取數據。添加額外的列,同時從兩個表中選擇
PreparedStatement ps = con.prepareStatement("(select * from web where name='abc') union (select * from mail where name='abc')");
ResultSet rs = ps.executeQuery();
while(rs.next()){
bw.write(rs3.getString("name")+"~"+rs3.getString("age")+"~"+rs3.getString("profession");
bw.newLine();
}
輸出是這樣的。
+------+------+------------+
| name | age | profession |
+------+------+------------+
| abc | 20 | doctor |
| abc | 20 | engineer |
+------+------+------------+
,並在文件中的像這樣
abc~20~doctor
abc~20~engineer
,但我怎麼能在結果集中,這將給我的數據,這種格式
abc~20~doctor~web
abc~20~engineer~mail
[檢查此解決方案](http://stackoverflow.com/questions/9836972/manually-add-data-to-a-java-resultset) – super