Advertisement
Guest User

Ramos Project

a guest
Apr 4th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 KB | None | 0 0
  1.  static  void getStatementTwo(String userTicker) {
  2.             Connection connection = getConnection();
  3.            
  4.             String query = "select * from TickerHistory where Ticker ='" +userTicker +"'group by ticker order by ticker";
  5.            
  6.             try {
  7.                 Statement statement = connection.createStatement();
  8.                 ResultSet rs = statement.executeQuery(query);
  9.                  int counter = 0 ;
  10.                 while (rs.next()) {
  11.                    
  12.                     counter ++;
  13.                     double openPrice = rs.getDouble("OpenPrice");
  14.                     int volume = rs.getInt("Volume");
  15.                     // you can use the name of the column or you can use the number of the column
  16.                     String companyName = rs.getString("CompanyName");
  17.                     String ticker = rs.getString("Ticker");
  18.                     System.out.println(counter + " " + ticker + " " + companyName + " " + volume + " " + openPrice);
  19.                    
  20.                    
  21.                 }
  22.                 rs.close();
  23.                 statement.close();
  24.                 connection.close();
  25.                
  26.                 rs = null;
  27.                 statement = null;
  28.                 connection = null;
  29.                
  30.             } catch (SQLException e) {
  31.                 System.out.println("SQLException: "+ e.getMessage());
  32.                 System.out.println("SQLState: "+ e.getSQLState());
  33.                 System.out.println("VendorError: "+ e.getErrorCode());
  34.             }
  35.         }
  36.     public static void main(String[] args) {
  37.        
  38.        
  39.         int userChoice;
  40.         Scanner one = new Scanner(System.in);
  41.         do{
  42.         System.out.println("\nWhat would you like to do?");
  43.         System.out.println("\n1. List all tickers.");
  44.         System.out.println("2. Search for The most recent data of a specific ticker.");
  45.         System.out.println("3. Search for the highest close price of a specific ticker.");
  46.         System.out.println("4. Show the top five traded tickers on a specific date. ");
  47.         System.out.println("5. Quit");
  48.         System.out.println("\nTo select what you would like to do please enter the number of your selection.");
  49.         userChoice = one.nextInt();
  50.        
  51.         if (userChoice == 1){
  52.             getAllTickers();
  53.             System.out.println("\n\n");
  54.         }
  55.         else if (userChoice == 2 ){
  56.             System.out.println("Please enter the ticker you want to look up. ");
  57.             Scanner two = new Scanner(System.in);
  58.             String userTicker = two.nextLine();
  59.             getStatementTwo(userTicker);
  60.             two.close();
  61.        
  62.    
  63.         }
  64.         else if (userChoice ==3){
  65.            
  66.         }
  67.         else if(userChoice ==4){
  68.             //Scanner four = new Scanner(System.in);
  69.             //System.out.println("Please enter the date you want in this format. \nxxxx-xx-xx (Year-Month-Day)");
  70.             //String specificDate = four.nextLine();
  71.            
  72.             getExampleQueries();
  73.         }
  74.         }
  75.         while (userChoice == 1 | userChoice == 2 | userChoice == 3 | userChoice == 4 );
  76.    
  77.        
  78.         one.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement