Advertisement
Guest User

aa

a guest
May 18th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. package muzica;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. import com.mysql.jdbc.Connection;
  11. import com.mysql.jdbc.Statement;
  12.  
  13.  
  14. public class MainApp {
  15.  
  16. public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException
  17. {
  18. //data base
  19.  
  20. String url = "jdbc:mysql://localhost:3306/test";
  21. Connection con = (Connection) DriverManager.getConnection(url,"root","root");
  22. Statement sql = (Statement) con.createStatement();
  23. ResultSet rs;
  24.  
  25. Class.forName("com.mysql.jdbc.Driver").newInstance();
  26. rs = sql.executeQuery("select * from muzica");
  27.  
  28.  
  29.  
  30.  
  31.  
  32. String indice = JOptionPane.showInputDialog("Dati indicele melodiei care doriti sa fie stearsa: ");
  33.  
  34. try {
  35. sql.executeUpdate("delete from muzica where id="+ "\""+indice+"\"");
  36. rs = sql.executeQuery("select * from muzica");
  37. rs.first();
  38.  
  39. } catch (SQLException e) {
  40. // TODO: handle exception
  41. System.out.println(e);
  42. }
  43.  
  44. ArrayList<Melodie> ls = new ArrayList<Melodie>();
  45. while(rs.next())
  46. {
  47.  
  48. Melodie mel = new Melodie(rs.getInt("id"),rs.getInt("An"),rs.getString("Artist"),rs.getString("Titlu"));
  49. ls.add(mel);
  50. }
  51.  
  52. for(Melodie item:ls)
  53. System.out.println(item);
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement