I have a table designed this way
mysql> select * from categories limit 50;
+-------------+-------------+-----------------+------------+------+------+------+------+------+------+------+
| category_id | T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 | T10 |
+-------------+-------------+-----------------+------------+------+------+------+------+------+------+------+
| 1 | Popcorn | Regular Pack | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 1 | Popcorn | Regular Pack | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 1 | Popcorn | Regular Pack | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | Popcorn | Bucket | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | Popcorn | Bucket | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 2 | Popcorn | Bucket | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 7 | Soft Drinks | Fountain | Apple | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 7 | Soft Drinks | Fountain | Apple | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 8 | Soft Drinks | Fountain | Orange | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 8 | Soft Drinks | Fountain | Orange | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 9 | Soft Drinks | Fountain | Lemon | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| 9 | Soft Drinks | Fountain | Lemon | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
我需要映射上表的数据。
示例xml文件,仅用于再结构
例如,
在爆米花下我必须有普通包装,水桶
在软饮料下我必须有喷泉,在喷泉下我必须有不同的类别苹果,橙子和柠檬
<Popcorn>
<Popcorn items>
< Regular Pack>
<Bucket >
</Popcorn items>
</Popcorn>
<Softdrinks>
<Softdrinks items>
<Fountain>
<Fountain items>
<Apple>
<Orange>
< Lemon>
</Fountain items>
</Softdrinks items>
一旦我检索了值,如何设置符合上述要求的条件??
psecoude代码对我来说也足够了
while(rs.next())
{
String T1 = rs.getString("T1");
String T2 = rs.getString("T2");
String T3 = rs.getString("T3");
String T4 = rs.getString("T4");
String T5 = rs.getString("T5");
String T6 = rs.getString("T6");
String T7 = rs.getString("T7");
String T8 = rs.getString("T8");
String T9 = rs.getString("T9");
String T10 = rs.getString("T10");
}
答案 0 :(得分:2)
据我所知
您需要通过此类查询获得两个不同的结果集
select DISTINCT T2 from tabelName where T1='PopCorn';
和
select DISTINCT T2 from tabelName where T1='SoftDrink';
您最好使用PreparedStatement
和ps.setString(0,"PopCorn");
对T2和T3应用相同的东西。
现在,您将在第一次查询后获得RegularPack and Bucket
,在第二次查询后获得Fountain
,然后根据需要使用这些值。