Advertisement
Guest User

Untitled

a guest
May 24th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /**
  2. * Created by Tanwir on 23-05-2017.
  3. */
  4. import java.sql.DriverManager
  5. import java.sql.Connection
  6. import com.typesafe.config._
  7. case class EmployeesCommission(first_name: String,
  8. last_name: String,
  9. salary: Double,
  10. commission_pct:Double) {
  11. override def toString(): String = {
  12. s"first_name: " + first_name + ";" + "last_name: " +last_name + ";"+ "commission_amount:" + getCommissionAmount()
  13. }
  14. def getCommissionAmount(): Any ={
  15. if(commission_pct==null){
  16. "Not Eligible"
  17. }else salary * commission_pct
  18. }
  19.  
  20. }
  21. object CommisionAmount {
  22.  
  23. def main(args: Array[String]): Unit ={
  24. val props = ConfigFactory.load() //will load the application.properties
  25. val driver = "com.mysql.jdbc.Driver"
  26. val host = props.getConfig(args(0)).getString("host")
  27. val port = props.getConfig(args(0)).getString("port")
  28. val db = props.getConfig(args(0)).getString("db")
  29. val url = "jdbc:mysql://" + host + ":" + port + "/" + db
  30. val username = props.getConfig(args(0)).getString("user")
  31. val password = props.getConfig(args(0)).getString("pw")
  32. Class.forName(driver)
  33.  
  34. val connection = DriverManager.getConnection(url, username, password)
  35. val statement = connection.createStatement()
  36. val resultSet = statement.executeQuery(s"SELECT first_name, last_name, " +
  37. "salary, commission_pct from employees")
  38. while ( resultSet.next() ) {
  39. val e = EmployeesCommission(resultSet.getString("first_name"),
  40. resultSet.getString("last_name"),
  41. resultSet.getDouble("salary"),
  42. resultSet.getDouble("commission_pct"))
  43. println(e)
  44. }
  45.  
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement