Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void closePrice(Scanner scann) {
- String line;
- System.out.println("Enter a valid ticker: ");
- line = scann.nextLine();
- Connection connection = getConnection();
- String query = "select HistoryDate, Ticker, HighPrice, ClosePrice from TickerHistory where Ticker = '" + line
- + "' order by ClosePrice desc limit 1";
- String query1 = "select HistoryDate, Ticker, HighPrice, ClosePrice from TickerHistory where Ticker = '" + line
- + "' order by HistoryDate desc limit 1";
- try {
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(query);
- ResultSet rs1 = statement.executeQuery(query1);
- while (rs.next() && rs1.next()) {
- double highClose = rs.getDouble("ClosePrice");
- String date = rs.getString("HistoryDate");
- double close = rs1.getDouble("ClosePrice");
- String date1 = rs1.getString("HistoryDate");
- for (int i = 1; i > 1; i++) {
- double difference = 1 - (close / highClose);
- double end = 100 * difference;
- System.out.println(date + " High Close Price: " + highClose);
- System.out.println(date1 + " Current Close Price: " + close);
- System.out.println("Perfect Difference: " + end + "%");
- }
- }
- rs.close();
- // rs1.close();
- statement.close();
- connection.close();
- rs = null;
- statement = null;
- connection = null;
- } catch (SQLException e) {
- System.out.println("SQLException: " + e.getMessage());
- System.out.println("SQLState: " + e.getSQLState());
- System.out.println("VendorError: " + e.getErrorCode());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement