Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package muzica;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import javax.swing.JOptionPane;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class MainApp {
- public static void main(String[] args) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException
- {
- //data base
- String url = "jdbc:mysql://localhost:3306/test";
- Connection con = (Connection) DriverManager.getConnection(url,"root","root");
- Statement sql = (Statement) con.createStatement();
- ResultSet rs;
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- rs = sql.executeQuery("select * from muzica");
- String indice = JOptionPane.showInputDialog("Dati indicele melodiei care doriti sa fie stearsa: ");
- try {
- sql.executeUpdate("delete from muzica where id="+ "\""+indice+"\"");
- rs = sql.executeQuery("select * from muzica");
- rs.first();
- } catch (SQLException e) {
- // TODO: handle exception
- System.out.println(e);
- }
- ArrayList<Melodie> ls = new ArrayList<Melodie>();
- while(rs.next())
- {
- Melodie mel = new Melodie(rs.getInt("id"),rs.getInt("An"),rs.getString("Artist"),rs.getString("Titlu"));
- ls.add(mel);
- }
- for(Melodie item:ls)
- System.out.println(item);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement