Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. package airTeague;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6.  
  7. public class AirTeagueHelper {
  8.  
  9. public Connection getConnection(){
  10. Connection con = null;
  11. try{
  12. Class.forName("oracle.jdbc.driver.OracleDriver");
  13. con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system","admin");
  14. }
  15. catch(Exception e){
  16. e.printStackTrace();
  17. System.out.println(e.getMessage());
  18. System.out.println(e.getCause());
  19. }
  20. return con;
  21. }
  22.  
  23. public int findDistance(String dep, String dest){
  24. int distance=0;
  25. try{
  26. Connection con = getConnection();
  27. Statement stmt = con.createStatement();
  28. String sql = "SELECT * FROM CITIES";
  29. ResultSet rs = stmt.executeQuery(sql);
  30. while(rs.next()){
  31. String city1 = rs.getString("CITY_1");
  32. String city2 = rs.getString("CITY_2");
  33. if(dep.equalsIgnoreCase(city1) || dep.equalsIgnoreCase(city2)){
  34. if(dest.equalsIgnoreCase(city1) || dest.equalsIgnoreCase(city2)){
  35. distance = rs.getInt("DISTANCE");
  36. }//end of inside loop
  37. }//end of total if
  38. }//end of while
  39. }//end of try
  40. catch(Exception e){
  41. e.printStackTrace();
  42. System.out.println(e.getMessage());
  43. System.out.println(e.getCause());
  44. }//end of catch
  45. return distance;
  46. }
  47.  
  48. public CityTempPair findDepartureInfo(String dep){
  49. CityTempPair departure = new CityTempPair();
  50. try{
  51. Connection con = getConnection();
  52. Statement stmt = con.createStatement();
  53. String sql = "SELECT * FROM CITIES";
  54. ResultSet rs = stmt.executeQuery(sql);
  55. while(rs.next()){
  56. String city1 = rs.getString("CITY_1");
  57. String city2 = rs.getString("CITY_2");
  58. if(dep.equalsIgnoreCase(city1)){
  59. int temp = rs.getInt("WEATHER_CITY_1");
  60. departure.setName(dep);
  61. departure.setTemp(temp);
  62. }
  63. else if(dep.equalsIgnoreCase(city2)){
  64. int temp = rs.getInt("WEATHER_CITY_2");
  65. departure.setName(dep);
  66. departure.setTemp(temp);
  67. }
  68. }//end of while loop
  69. }catch(Exception e){
  70. e.printStackTrace();
  71. System.out.println(e.getMessage());
  72. System.out.println(e.getCause());
  73. }
  74. return departure;
  75. }
  76.  
  77. public CityTempPair findDestinationInfo(String dest){
  78. CityTempPair destination = new CityTempPair();
  79. try{
  80. Connection con = getConnection();
  81. Statement stmt = con.createStatement();
  82. String sql = "SELECT * FROM CITIES";
  83. ResultSet rs = stmt.executeQuery(sql);
  84. while(rs.next()){
  85. String city1 = rs.getString("CITY_1");
  86. String city2 = rs.getString("CITY_2");
  87. if(dest.equalsIgnoreCase(city1)){
  88. int temp = rs.getInt("WEATHER_CITY_1");
  89. destination.setName(dest);
  90. destination.setTemp(temp);
  91. }
  92. else if(dest.equalsIgnoreCase(city2)){
  93. int temp = rs.getInt("WEATHER_CITY_2");
  94. destination.setName(dest);
  95. destination.setTemp(temp);
  96. }
  97. }//end of while loop
  98. }catch(Exception e){
  99. e.printStackTrace();
  100. System.out.println(e.getMessage());
  101. System.out.println(e.getCause());
  102. }
  103. return destination;
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement