Added method to get all shops
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package de.dis2017.data.db;
|
package de.dis2017.data.db;
|
||||||
|
|
||||||
import de.dis2017.data.Article;
|
import de.dis2017.data.Article;
|
||||||
|
import de.dis2017.data.Shop;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@ -52,4 +53,37 @@ public class ORM {
|
|||||||
|
|
||||||
return articles;
|
return articles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Shop> getShops()
|
||||||
|
{
|
||||||
|
List<Shop> shops = new ArrayList<>();
|
||||||
|
String selectSQL = "SELECT s.shopID, s.name AS name, c.name AS city, " +
|
||||||
|
"r.name AS region, n.name AS country " +
|
||||||
|
"FROM DB2INST1.SHOPID AS s, DB2INST1.STADTID AS c," +
|
||||||
|
"DB2INST1.REGIONID r, DB2INST1.LANDID AS n " +
|
||||||
|
"WHERE s.STADTID = c.STADTID " +
|
||||||
|
"AND c.REGIONID = r.REGIONID " +
|
||||||
|
"AND r.LANDID = n.LANDID";
|
||||||
|
try {
|
||||||
|
PreparedStatement pstmt = _connection.prepareStatement(selectSQL);
|
||||||
|
ResultSet rs = pstmt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Shop shop = new Shop();
|
||||||
|
shop.set_shopID(rs.getInt("shopID"));
|
||||||
|
shop.set_name(rs.getString("name"));
|
||||||
|
shop.set_city(rs.getString("city"));
|
||||||
|
shop.set_region(rs.getString("region"));
|
||||||
|
shop.set_country(rs.getString("country"));
|
||||||
|
shops.add(shop);
|
||||||
|
}
|
||||||
|
|
||||||
|
rs.close();
|
||||||
|
pstmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return shops;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user