//========================================================================
//Program: IDEA_Welcome.java
//
// Author:  F2-Team2
// This is a sample program written for the UIT2201 Project
//
// This program takes input a number
// output: message.
//
//
package IDEA_Welcome;
import java.sql.*;   // LHW: this imports sql related classes
import DBClasses.*;  // LHW: imports database manager and other classes
import java.util.*;

class Welcome {

  public static void main(String[] args) {

	 String num = args[0];
     int index = Integer.parseInt(num);

     // LHW: Create a database connection
     // LHW:  by using the dbManager class provided
     dbManager dbman = new dbManager();
     Connection conn = dbman.getConnection();

     Vector v = new Vector();

     try {
       // To execute query,
       //   first create the sql statement
       //   execute the statement
       //   "catch" the output in "rs" (rs is a set of tuples)
       Statement stmt = conn.createStatement();
       String sql = "SELECT wel_txt FROM Welcome WHERE wel_type = '"+index+"'";
            // prepare sql stmt
       ResultSet rs = stmt.executeQuery(sql);          // execute query

       while (rs.next()) {                             // process the result

           v.addElement(rs.getString("wel_txt"));

       }

       Random rand=new Random();

	   int n=rand.nextInt(v.size());
       System.out.println((String) v.elementAt(n));// output the result;


       rs.close();       // close everything (rs, stmt, conn)
       stmt.close();
       conn.close();
    } catch (Exception e) {
      //System.out.println("DB Error!"); // error message if exception occurs
      //e.printStackTrace();
      System.out.println("Not Found");
    }

  }
}
