Advertisement
JVFabia

test

Oct 7th, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package org.forge.jdbc;
  2.  
  3. import java.sql.*;
  4. import java.util.Scanner;
  5.  
  6. public class ConnectionTest {
  7.     public static void main(String[] args) throws SQLException {
  8.         Connection conn = DriverManager.getConnection(
  9.                 "jdbc:postgresql://forgedb.netbyteoss.com:5443/forge_alumnos","alumno1","alumno.01"
  10.         );
  11.  
  12.         Scanner sc = new Scanner(System.in);
  13.         System.out.println("ingrese una pelicula");
  14.         String pelicula = sc.nextLine();
  15.         String consulta = "SELECT TOP 3 * FROM pelicula " +
  16.                 "WHERE nombre Like ? ORDER BY calificacion DESC";
  17.         PreparedStatement ps = conn.prepareStatement(consulta);
  18.         ps.setString(1, pelicula);
  19.         ResultSet rs = ps.executeQuery();
  20.         while(rs.next()){
  21.             System.out.print(rs.getString("nombre")+": ");
  22.             System.out.println(rs.getDouble("calificacion"));
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement