Guest User

Untitled

a guest
Jan 8th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package mysqlconn;
  2.  
  3. import java.sql.*;
  4. import java.util.*;
  5.  
  6.  
  7. public class Mysqlconn {
  8.  
  9. public static void main(String[] args)throws SQLException {
  10.  
  11. try {
  12. String url="jdbc:mysql://localhost:3306/newdatabase";
  13.  
  14. Properties prop=new Properties();
  15. prop.setProperty("user","root");
  16. prop.setProperty("password","");
  17.  
  18. Driver d = new com.mysql.jdbc.Driver();
  19. Connection con = d.connect(url,prop);
  20.  
  21. if(con == null) {
  22. System.out.println("connection failed");
  23. return;
  24. }
  25. // these are variables to insert
  26. String fname = "Tarek";
  27.  
  28.  
  29. String query1 = "DELETE FROM user WHERE first_name = 'Sifat';
  30. String query2 = "DELETE FROM user WHERE first_name = '" + fname + "'";
  31.  
  32. Statement state = con.createStatement();
  33. ResultSet result = null;
  34.  
  35. state.executeUpdate(query1);
  36. state.executeUpdate(query2);
  37.  
  38. state.close();
  39. } catch (Exception e)
  40. {
  41. System.err.println("Got an exception!");
  42. System.err.println(e.getMessage());
  43. }
  44.  
  45. }
  46. }
Add Comment
Please, Sign In to add comment