Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class Main2 {
- private static final String TWO_IN_ONE = "SELECT * FROM movies WHERE rating > (SELECT AVG(rating) as aver FROM movies);";
- public static void main(String[] args) {
- try (Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/cinemas_ex", "root",
- "coderslab");
- PreparedStatement prepStat = connection.prepareStatement(TWO_IN_ONE);
- ResultSet resultSet = prepStat.executeQuery();) {
- while (resultSet.next()) {
- System.out.println(resultSet.getInt("id") + " " + resultSet.getString("name") + " "
- + resultSet.getString("description") + " " + resultSet.getDouble("rating"));
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement