Previn

Update_db

Sep 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.  
  2. package test_database;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8.  
  9. public class Update_db {
  10.    
  11.      public static void main(String []arg)
  12.      {
  13.                      
  14.         Connection con;
  15.         PreparedStatement ps;
  16.         ResultSet rs;        
  17.        
  18.         try
  19.         {
  20.             Class.forName("com.mysql.jdbc.Driver");
  21.             con=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
  22.             System.out.println("Database Connected");      
  23.            
  24.             //Update query
  25.             ps=con.prepareStatement("update test_db set Rollno=? where Name=?");
  26.             ps.setString(1,"621615104069");
  27.             ps.setString(2,"Previnkumar");
  28.             ps.executeUpdate();
  29.             System.out.println("Updated Successfully");
  30.  
  31.  
  32.         }
  33.         catch(Exception e)
  34.         {
  35.             System.out.println(e);
  36.         }
  37.  
  38.     }
  39.            
  40. }
Add Comment
Please, Sign In to add comment