Guest User

Untitled

a guest
Jan 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 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 d = rs.getString(1);
  22. int result = d.compareTo("78");
  23. //System.out.print(result);
  24. if(result==0){ d="tm";}
  25. if(result<0)
  26. {
  27. d = "th";
  28.  
  29. }
  30. else
  31. {
  32. d ="tl";
  33. }
  34. // System.out.println(d);
  35. String query1 =" update ri set temp= d ";
  36. Statement stmt1 = conn.createStatement();
  37. stmt1.executeUpdate(query1);
  38.  
  39.  
  40. } //end whil
  41. }
  42. catch (Exception e)
  43. {
  44. System.err.println ("Cannot connect to database server");
  45. }
  46. finally
  47. {
  48. if (conn != null)
  49. {
  50. try
  51. {
  52. conn.close ();
  53. System.out.println ("Database connection terminated");
  54. }
  55. catch (Exception e) { /* ignore close errors */ }
  56. }
  57. }
  58. }
  59. }
Add Comment
Please, Sign In to add comment