Guest User

Untitled

a guest
Jan 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. import java.sql.*;
  2. public class Connect
  3. {
  4. public static void main (String[] args)
  5. {
  6. Connection conn = null;
  7. try
  8. {
  9. String userName = "root";
  10. String password = "123";
  11. String url = "jdbc:mysql://localhost/typhoon";
  12. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  13. conn = DriverManager.getConnection (url, userName, password);
  14. System.out.println ("Database connection establiished");
  15. String query = "Select * From typhoon";
  16. Statement stmt = conn.createStatement();
  17. ResultSet rs = stmt.executeQuery(query);
  18. while (rs.next())
  19. {
  20.  
  21. // this query for TEMP attribute
  22. String di = rs.getString(1);
  23. int result = di.compareTo("78");
  24. //System.out.print(result);
  25. if(result==0){ di="tm";}
  26. if(result>0) { di = "th";}
  27. else { di ="tl"; }
  28. // System.out.println(di);
  29. String query1 = "update typhoon set TEMP=" +"\"" + di+"\"";
  30. Statement stmt1 = conn.createStatement();
  31. stmt1.executeUpdate(query1);
  32. // this query for DEWP attribute
  33.  
  34. String d1 = rs.getString(2);
  35. int result1 = d1.compareTo("70");
  36. if(result1==0){ d1="dm";}
  37. if(result1>0) { d1 = "dh";}
  38. else { d1 ="dl"; }
  39. System.out.println(d1);
  40. String query2 = "update typhoon set DEWP=" +"\"" + d1+"\"";
  41. Statement stmt2 = conn.createStatement();
  42. stmt2.executeUpdate(query2);
  43. // this query for WDSP attribute
  44.  
  45. String d2 = rs.getString(3);
  46. int result2 = d2.compareTo("7.0");
  47. if(result2==0){ d2="wm";}
  48. if(result2>0) { d2 = "wh";}
  49. else { d2 ="wl"; }
  50. System.out.println(d2);
  51. String query3 = "update typhoon set WDSP=" +"\"" + d2+"\"";
  52. Statement stmt3 = conn.createStatement();
  53. stmt3.executeUpdate(query3);
  54. // this query for VISIB attribute
  55.  
  56. String d3 = rs.getString(4);
  57. int result3 = d3.compareTo("4.7");
  58. if(result3==0){ d3="vm";}
  59. if(result3>0) { d3 = "vh";}
  60. else { d3 ="vl"; }
  61. System.out.println(d3);
  62. String query4 = "update typhoon set VISIB=" +"\"" + d3+"\"";
  63. Statement stmt4 = conn.createStatement();
  64. stmt4.executeUpdate(query4);
  65. // this query for PRCP attribute
  66.  
  67. String d4 = rs.getString(5);
  68. int result4 = d4.compareTo("0");
  69. if(result4==0){ d4="yes";}
  70. else { d4 ="no"; }
  71. System.out.println(d4);
  72. String query5 = "update typhoon set PRCP=" +"\"" + d4+"\"";
  73. Statement stmt5 = conn.createStatement();
  74. stmt5.executeUpdate(query5);
  75.  
  76.  
  77. } //end while
  78. }
  79. catch (Exception e)
  80. {
  81. System.err.println ("Cannot connect to database server");
  82. }
  83. finally
  84. {
  85. if (conn != null)
  86. {
  87. try
  88. {
  89. conn.close ();
  90. System.out.println ("Database connection terminated");
  91. }
  92. catch (Exception e) { /* ignore close errors */ }
  93. }
  94. }
  95. }
  96. }
Add Comment
Please, Sign In to add comment