user3674364
user3674364

Reputation: 69

How do i put a condition for matching the above requirement

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 |

I need to map the data of the above table .

a sample xml file , just to repersent structure

For example ,

Under Popcorn i must have Regular Pack , Bucket

And under Soft Drinks i must have Fountain , and under Fountain i must have different categories Apple ,Orange and Lemon

 <Popcorn>
    <Popcorn items>
     < Regular Pack>
     <Bucket >
    </Popcorn items>
    </Popcorn>

    <Softdrinks>
    <Softdrinks items>
    <Fountain>
<Fountain items>
    <Apple>
    <Orange>
    < Lemon>
</Fountain items>
    </Softdrinks items>

Once i retrive the values , how to put a condition that matches the above requirement ??

A psecoude code will be also sufficient for me to proccedd

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");
}

Upvotes: 0

Views: 37

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 23002

According to me

  • You need to get two different resultset for this by quering like this

    1. select DISTINCT T2 from tabelName where T1='PopCorn'; and

    2. select DISTINCT T2 from tabelName where T1='SoftDrink';

You better use PreparedStatement for this and ps.setString(0,"PopCorn");

Apply same thing for T2 and T3.

Now you will have RegularPack and Bucket after first query and Fountain after second and than use these values as you want to.

Upvotes: 2

Related Questions