Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/products_ex?useSSL=false",
- "root", "dupa");
- ) {
- Statement statement = conn.createStatement();
- ResultSet set = statement.executeQuery("SELECT * FROM Products");
- while(set.next()) {
- int currentId = set.getInt("id") ;
- String output = "ID: " + currentId + " |Name : " + set.getString("name") +
- " |Description : " + set.getString("description") +
- " |Price: " + set.getDouble("price");
- Statement ordersStatement = conn.createStatement();
- System.out.println(output);
- ResultSet ordersSet =
- ordersStatement.executeQuery("SELECT order_id FROM Orders_Products WHERE product_id =" + currentId );
- while(ordersSet.next()) {
- System.out.println("Zamówiony w zamówieniu o id: "+ ordersSet.getInt("order_id"));
- }
- }
- }catch(SQLException exc) {
- exc.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement