Advertisement
Guest User

Untitled

a guest
Jan 28th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. public static void main(String[] args) {
  3. try (Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/products_ex?useSSL=false",
  4. "root", "dupa");
  5. ) {
  6. Statement statement = conn.createStatement();
  7. ResultSet set = statement.executeQuery("SELECT * FROM Products");
  8. while(set.next()) {
  9. int currentId = set.getInt("id") ;
  10. String output = "ID: " + currentId + " |Name : " + set.getString("name") +
  11. " |Description : " + set.getString("description") +
  12. " |Price: " + set.getDouble("price");
  13. Statement ordersStatement = conn.createStatement();
  14. System.out.println(output);
  15. ResultSet ordersSet =
  16. ordersStatement.executeQuery("SELECT order_id FROM Orders_Products WHERE product_id =" + currentId );
  17. while(ordersSet.next()) {
  18. System.out.println("Zamówiony w zamówieniu o id: "+ ordersSet.getInt("order_id"));
  19. }
  20. }
  21.  
  22. }catch(SQLException exc) {
  23. exc.printStackTrace();
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement