Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package databaseproject;
- import static databaseproject.DatabaseProject.testDB;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author jonaspedersen
- */
- public class opg2 {
- public static void main(String[] args) {
- String url = "jdbc:postgresql://localhost:5432/postgres";
- String user = "postgres";
- String password = "Snuden123";
- Connection con = null;
- //CONNECTING
- try {
- con = DriverManager.getConnection(url, user, password);
- } catch (SQLException ex) {
- Logger lgr = Logger.getLogger(DatabaseProject.class.getName());
- lgr.log(Level.WARNING, ex.getMessage(), ex);
- }
- opgaveSolver(con);
- }
- public static void opgaveSolver(Connection con){
- Scanner sc1 = new Scanner(System.in);
- Scanner sc2 = new Scanner(System.in);
- Scanner sc3 = new Scanner(System.in);
- Scanner sc4 = new Scanner(System.in);
- System.out.println("Angiv laveste hastighed");
- int userSpeed = sc1.nextInt();
- System.out.println("Angiv ram");
- int ramSpeed = sc2.nextInt();
- System.out.println("Angiv harddisk størrelse");
- int hdSize = sc3.nextInt();
- System.out.println("Angiv skærmstørrelse");
- float screenSize = sc4.nextFloat();
- try{
- PreparedStatement st = con.prepareStatement("SELECT speed, ram, screen, hd FROM laptop WHERE speed >" +userSpeed+ "AND ram >" +ramSpeed+ "AND hd >" +hdSize+ "AND screen >" +screenSize);
- ResultSet rs = st.executeQuery();
- while(rs.next()){
- System.out.println("Hastighed " + rs.getInt(1) + " ram " +rs.getInt(2) + " skærmstørrelse " + rs.getInt(3) + " harddisk " +rs.getInt(4) + "\n");
- }
- }catch(SQLException e){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement