Advertisement
Guest User

Untitled

a guest
Mar 16th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package databaseproject;
  7.  
  8. import static databaseproject.DatabaseProject.testDB;
  9. import java.sql.Connection;
  10. import java.sql.DriverManager;
  11. import java.sql.PreparedStatement;
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.util.Scanner;
  15. import java.util.logging.Level;
  16. import java.util.logging.Logger;
  17.  
  18. /**
  19.  *
  20.  * @author jonaspedersen
  21.  */
  22. public class opg2 {
  23.    
  24.    
  25.         public static void main(String[] args) {
  26.         String url = "jdbc:postgresql://localhost:5432/postgres";
  27.         String user = "postgres";
  28.         String password = "Snuden123";
  29.         Connection con = null;
  30.  
  31.         //CONNECTING
  32.         try {
  33.             con = DriverManager.getConnection(url, user, password);
  34.  
  35.         } catch (SQLException ex) {
  36.                 Logger lgr = Logger.getLogger(DatabaseProject.class.getName());
  37.                 lgr.log(Level.WARNING, ex.getMessage(), ex);
  38.  
  39.         }
  40.  
  41.         opgaveSolver(con);
  42.     }
  43.        
  44.         public static void opgaveSolver(Connection con){
  45.             Scanner sc1 = new Scanner(System.in);
  46.             Scanner sc2 = new Scanner(System.in);
  47.             Scanner sc3 = new Scanner(System.in);
  48.             Scanner sc4 = new Scanner(System.in);
  49.            
  50.             System.out.println("Angiv laveste hastighed");
  51.             int userSpeed = sc1.nextInt();
  52.            
  53.             System.out.println("Angiv ram");
  54.             int ramSpeed = sc2.nextInt();
  55.            
  56.             System.out.println("Angiv harddisk størrelse");
  57.             int hdSize = sc3.nextInt();
  58.            
  59.             System.out.println("Angiv skærmstørrelse");
  60.             float screenSize = sc4.nextFloat();
  61.            
  62.             try{
  63.                
  64.                 PreparedStatement st = con.prepareStatement("SELECT speed, ram, screen, hd FROM laptop WHERE speed >" +userSpeed+ "AND ram >" +ramSpeed+ "AND hd >" +hdSize+ "AND screen >" +screenSize);
  65.                 ResultSet rs = st.executeQuery();
  66.                 while(rs.next()){
  67.                     System.out.println("Hastighed " + rs.getInt(1) + " ram " +rs.getInt(2) + " skærmstørrelse " + rs.getInt(3) + " harddisk " +rs.getInt(4) + "\n");
  68.                 }
  69.                
  70.                }catch(SQLException e){
  71.                
  72.             }
  73.         }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement