Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class convert
- {
- public static void main (String[] args)
- {
- Connection conn = null;
- try
- {
- String userName = "root";
- String password = "123";
- String url = "jdbc:mysql://localhost/test";
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- conn = DriverManager.getConnection (url, userName, password);
- System.out.println ("Database connection establiished");
- String query = "Select * From ri";
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- String d = rs.getString(1);
- int result = d.compareTo("78");
- //System.out.print(result);
- if(result==0){ d="tm";}
- if(result<0)
- {
- d = "th";
- }
- else
- {
- d ="tl";
- }
- // System.out.println(d);
- String query1 =" update ri set temp= d ";
- Statement stmt1 = conn.createStatement();
- stmt1.executeUpdate(query1);
- } //end whil
- }
- catch (Exception e)
- {
- System.err.println ("Cannot connect to database server");
- }
- finally
- {
- if (conn != null)
- {
- try
- {
- conn.close ();
- System.out.println ("Database connection terminated");
- }
- catch (Exception e) { /* ignore close errors */ }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment