Previn

Delete_db

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