Advertisement
Guest User

Untitled

a guest
May 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6.  
  7. public class Main2 {
  8.  
  9. private static final String TWO_IN_ONE = "SELECT * FROM movies WHERE rating > (SELECT AVG(rating) as aver FROM movies);";
  10.  
  11. public static void main(String[] args) {
  12.  
  13. try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root",
  14. "coderslab");
  15. PreparedStatement prepStat = connection.prepareStatement(TWO_IN_ONE);
  16. ResultSet resultSet = prepStat.executeQuery();) {
  17. while (resultSet.next()) {
  18.  
  19. System.out.println(resultSet.getInt("id") + " " + resultSet.getString("name") + " "
  20. + resultSet.getString("description") + " " + resultSet.getDouble("rating"));
  21.  
  22. }
  23.  
  24. } catch (SQLException e) {
  25. // TODO Auto-generated catch block
  26. e.printStackTrace();
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement