Guest User

Untitled

a guest
Jan 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class convert
  4. {
  5. public static void main (String[] args)
  6. {
  7. Connection conn = null;
  8.  
  9. try
  10. {
  11. String userName = "root";
  12. String password = "123";
  13. String url = "jdbc:mysql://localhost/test";
  14. Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  15. conn = DriverManager.getConnection (url, userName, password);
  16. System.out.println ("Database connection establiished");
  17. String query = "Select * From ri";
  18. Statement stmt = conn.createStatement();
  19. ResultSet rs = stmt.executeQuery(query);
  20. while (rs.next()) {
  21. String di = rs.getString(1);
  22. int result = di.compareTo("78");
  23. //System.out.print(result);
  24. if(result==0){ di="tm";}
  25. if(result<0)
  26. {
  27. di = "th";
  28.  
  29. }
  30. else
  31. {
  32. di ="tl";
  33. }
  34. //System.out.println(di);
  35. String query1 = "update ri set temp=" +"\"" + di+"\"";
  36. // String query1 = "update ri set temp=" + di;
  37. Statement stmt1 = conn.createStatement();
  38. stmt1.executeQuery(query1);
  39.  
  40.  
  41. } //end while
  42. }
  43. catch (Exception e)
  44. {
  45. System.err.println ("Cannot connect to database server");
  46. }
  47. finally
  48. {
  49. if (conn != null)
  50. {
  51. try
  52. {
  53. conn.close ();
  54. System.out.println ("Database connection terminated");
  55. }
  56. catch (Exception e) { /* ignore close errors */ }
  57. }
  58. }
  59. }
  60. }
Add Comment
Please, Sign In to add comment