Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void getStatementTwo(String userTicker) {
- Connection connection = getConnection();
- String query = "select * from TickerHistory where Ticker ='" +userTicker +"'group by ticker order by ticker";
- try {
- Statement statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(query);
- int counter = 0 ;
- while (rs.next()) {
- counter ++;
- double openPrice = rs.getDouble("OpenPrice");
- int volume = rs.getInt("Volume");
- // you can use the name of the column or you can use the number of the column
- String companyName = rs.getString("CompanyName");
- String ticker = rs.getString("Ticker");
- System.out.println(counter + " " + ticker + " " + companyName + " " + volume + " " + openPrice);
- }
- rs.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());
- }
- }
- public static void main(String[] args) {
- int userChoice;
- Scanner one = new Scanner(System.in);
- do{
- System.out.println("\nWhat would you like to do?");
- System.out.println("\n1. List all tickers.");
- System.out.println("2. Search for The most recent data of a specific ticker.");
- System.out.println("3. Search for the highest close price of a specific ticker.");
- System.out.println("4. Show the top five traded tickers on a specific date. ");
- System.out.println("5. Quit");
- System.out.println("\nTo select what you would like to do please enter the number of your selection.");
- userChoice = one.nextInt();
- if (userChoice == 1){
- getAllTickers();
- System.out.println("\n\n");
- }
- else if (userChoice == 2 ){
- System.out.println("Please enter the ticker you want to look up. ");
- Scanner two = new Scanner(System.in);
- String userTicker = two.nextLine();
- getStatementTwo(userTicker);
- two.close();
- }
- else if (userChoice ==3){
- }
- else if(userChoice ==4){
- //Scanner four = new Scanner(System.in);
- //System.out.println("Please enter the date you want in this format. \nxxxx-xx-xx (Year-Month-Day)");
- //String specificDate = four.nextLine();
- getExampleQueries();
- }
- }
- while (userChoice == 1 | userChoice == 2 | userChoice == 3 | userChoice == 4 );
- one.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement