private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        try {
            // TODO add your handling code here:
            try {
                clip.stop();
            }
            catch(Exception e) {
            }
            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AdminView.class.getName()).log(Level.SEVERE, null, ex);
            }
            //step2 create  the connection object
            Connection con=DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345");
            //step3 create the statement object
            Statement stmt=con.createStatement();
            //step4 execute query
            ResultSet rs=stmt.executeQuery("select * from album");
            ArrayList<String> albumList = new ArrayList<String>();
            HashMap<String, String> albumID = new HashMap<>();
            while(rs.next()) {
                albumList.add((rs.getString(2)));
                albumID.put(rs.getString(2), rs.getString(1));
            }
            //step4 execute query
            rs=stmt.executeQuery("select * from artist");
            ArrayList<String> artistList = new ArrayList<String>();
            HashMap<String, String> artistID = new HashMap<>();
            while(rs.next()) {
                artistList.add((rs.getString(2)));
                artistID.put(rs.getString(2), rs.getString(1));
            }
            //step5 close the connection object
            con.close();
            // TODO add your handling code here:
//            JTextField id = new JTextField();
            JTextField name = new JTextField();
            JTextField genre = new JTextField();
            JTextField song_num = new JTextField();
            JComboBox<String> albums = new JComboBox<String>(albumList.toArray(new String[0]));
            JList artists = new JList(artistList.toArray(new String[0]));
            artists.setSelectionMode(
            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            int[] select = {19, 20, 22};
            Object[] input = {
//                "Id : ", id,
                "Name : ", name,
                "Genre :", genre,
                "Artist :", artists,
                "Song Number in Album :", song_num,
                "Album :", albums,
            };
            int option = JOptionPane.showConfirmDialog(this, input, "Enter Song details", JOptionPane.OK_CANCEL_OPTION);
            if(option == JOptionPane.OK_OPTION) {
                JFileChooser jfc = new JFileChooser();
		int returnValue = jfc.showOpenDialog(null);
		// int returnValue = jfc.showSaveDialog(null);
                String filePath = null;
		if (returnValue == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = jfc.getSelectedFile();
                    System.out.println(selectedFile.getAbsolutePath());
                    filePath = selectedFile.getAbsolutePath();
                }
                 try{  
                    File f=new File(filePath);  
                    Class.forName("oracle.jdbc.driver.OracleDriver");  
                    con = DriverManager.getConnection(
                             "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345");
                    PreparedStatement ps = con.prepareStatement ("insert into song values(?, ?, ?, ?, ?, ?, ?)");
                    ps.setString(1, null);  
                    ps.setString(2, name.getText());
                    ps.setString(3, albumID.get(albums.getSelectedItem().toString()));
                    ps.setString(4, genre.getText());
                    ps.setInt(5, 0);
                    ps.setInt(6, Integer.parseInt(song_num.getText()));
                    System.out.println(""+f.length());
                    ps.setBytes(7, readFile(filePath));
                    ps.executeUpdate();
                    ps.close();
                    PreparedStatement ps1 = con.prepareStatement ("select id from song where name=? and album_id=?");
                    ps1.setString(1, name.getText());  
                    ps1.setString(2, albumID.get(albums.getSelectedItem().toString()));
                    //step4 execute query
                    ResultSet rs1=ps1.executeQuery();
                    String id = "";
                    while(rs1.next()) {
                        id = rs1.getString(1);
                    }
                    ps1.close();
                    for(Object a:artists.getSelectedValuesList()) {
                        ps = con.prepareCall ("{call addsongartist(?, ?)}");
                        ps.setString(1, id);  
                        ps.setString(2, artistID.get(a.toString()));
                        ps.executeUpdate();
                        ps.close();
                    }
                    con.close();  
                } catch (Exception e) {e.printStackTrace();}  
                this.updateTable();
                JOptionPane.showMessageDialog(this, "Success!\n");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error!\n"+e.getMessage());
        }
    }
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {        try {
           
            try {
                clip.stop();
            }
            catch(Exception e) {
            }
            try {
                Class.forName("oracle.jdbc.driver.OracleDriver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(AdminView.class.getName()).log(Level.SEVERE, null, ex);
            }
           
            Connection con=DriverManager.getConnection(
                    "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345");
           
            Statement stmt=con.createStatement();
           
            ResultSet rs=stmt.executeQuery("select * from album");
            ArrayList<String> albumList = new ArrayList<String>();
            HashMap<String, String> albumID = new HashMap<>();
            while(rs.next()) {
                albumList.add((rs.getString(2)));
                albumID.put(rs.getString(2), rs.getString(1));
            }
           
            rs=stmt.executeQuery("select * from artist");
            ArrayList<String> artistList = new ArrayList<String>();
            HashMap<String, String> artistID = new HashMap<>();
            while(rs.next()) {
                artistList.add((rs.getString(2)));
                artistID.put(rs.getString(2), rs.getString(1));
            }
           
            con.close();
           
            JTextField name = new JTextField();
            JTextField genre = new JTextField();
            JTextField song_num = new JTextField();
            JComboBox<String> albums = new JComboBox<String>(albumList.toArray(new String[0]));
            JList artists = new JList(artistList.toArray(new String[0]));
            artists.setSelectionMode(
            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            int[] select = {19, 20, 22};
            Object[] input = {
                "Name : ", name,
                "Genre :", genre,
                "Artist :", artists,
                "Song Number in Album :", song_num,
                "Album :", albums,
            };
            int option = JOptionPane.showConfirmDialog(this, input, "Enter Song details", JOptionPane.OK_CANCEL_OPTION);
            if(option == JOptionPane.OK_OPTION) {
                JFileChooser jfc = new JFileChooser();
		int returnValue = jfc.showOpenDialog(null);
	
                String filePath = null;
		if (returnValue == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = jfc.getSelectedFile();
                    System.out.println(selectedFile.getAbsolutePath());
                    filePath = selectedFile.getAbsolutePath();
                }
                 try{  
                    File f=new File(filePath);  
                    Class.forName("oracle.jdbc.driver.OracleDriver");  
                    con = DriverManager.getConnection(
                             "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345");
                    PreparedStatement ps = con.prepareStatement ("insert into song values(?, ?, ?, ?, ?, ?, ?)");
                    ps.setString(1, null);  
                    ps.setString(2, name.getText());
                    ps.setString(3, albumID.get(albums.getSelectedItem().toString()));
                    ps.setString(4, genre.getText());
                    ps.setInt(5, 0);
                    ps.setInt(6, Integer.parseInt(song_num.getText()));
                    System.out.println(""+f.length());
                    ps.setBytes(7, readFile(filePath));
                    ps.executeUpdate();
                    ps.close();
                    PreparedStatement ps1 = con.prepareStatement ("select id from song where name=? and album_id=?");
                    ps1.setString(1, name.getText());  
                    ps1.setString(2, albumID.get(albums.getSelectedItem().toString()));
                   
                    ResultSet rs1=ps1.executeQuery();
                    String id = "";
                    while(rs1.next()) {
                        id = rs1.getString(1);
                    }
                    ps1.close();
                    for(Object a:artists.getSelectedValuesList()) {
                        ps = con.prepareCall ("{call addsongartist(?, ?)}");
                        ps.setString(1, id);  
                        ps.setString(2, artistID.get(a.toString()));
                        ps.executeUpdate();
                        ps.close();
                    }
                    con.close();  
                } catch (Exception e) {e.printStackTrace();}  
                this.updateTable();
                JOptionPane.showMessageDialog(this, "Success!\n");
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error!\n"+e.getMessage());
        }
    }
private void addbuttonactionperformed(java.awt.event.actionevent evt) { try { try { clip.stop(); } catch(exception e) { } try { class.forname("oracle.jdbc.driver.oracledriver"); } catch (classnotfoundexception ex) { logger.getlogger(adminview.class.getname()).log(level.severe, null, ex); } connection con=drivermanager.getconnection( "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345"); statement stmt=con.createstatement(); resultset rs=stmt.executequery("select * from album"); arraylist<string> albumlist = new arraylist<string>(); hashmap<string, string> albumid = new hashmap<>(); while(rs.next()) { albumlist.add((rs.getstring(2))); albumid.put(rs.getstring(2), rs.getstring(1)); } rs=stmt.executequery("select * from artist"); arraylist<string> artistlist = new arraylist<string>(); hashmap<string, string> artistid = new hashmap<>(); while(rs.next()) { artistlist.add((rs.getstring(2))); artistid.put(rs.getstring(2), rs.getstring(1)); } con.close(); jtextfield name = new jtextfield(); jtextfield genre = new jtextfield(); jtextfield song_num = new jtextfield(); jcombobox<string> albums = new jcombobox<string>(albumlist.toarray(new string[0])); jlist artists = new jlist(artistlist.toarray(new string[0])); artists.setselectionmode( listselectionmodel.multiple_interval_selection); int[] select = {19, 20, 22}; object[] input = { "name : ", name, "genre :", genre, "artist :", artists, "song number in album :", song_num, "album :", albums, }; int option = joptionpane.showconfirmdialog(this, input, "enter song details", joptionpane.ok_cancel_option); if(option == joptionpane.ok_option) { jfilechooser jfc = new jfilechooser(); int returnvalue = jfc.showopendialog(null); string filepath = null; if (returnvalue == jfilechooser.approve_option) { file selectedfile = jfc.getselectedfile(); system.out.println(selectedfile.getabsolutepath()); filepath = selectedfile.getabsolutepath(); } try{ file f=new file(filepath); class.forname("oracle.jdbc.driver.oracledriver"); con = drivermanager.getconnection( "jdbc:oracle:thin:@localhost:1521:newdatabase","system","not12345"); preparedstatement ps = con.preparestatement ("insert into song values(?, ?, ?, ?, ?, ?, ?)"); ps.setstring(1, null); ps.setstring(2, name.gettext()); ps.setstring(3, albumid.get(albums.getselecteditem().tostring())); ps.setstring(4, genre.gettext()); ps.setint(5, 0); ps.setint(6, integer.parseint(song_num.gettext())); system.out.println(""+f.length()); ps.setbytes(7, readfile(filepath)); ps.executeupdate(); ps.close(); preparedstatement ps1 = con.preparestatement ("select id from song where name=? and album_id=?"); ps1.setstring(1, name.gettext()); ps1.setstring(2, albumid.get(albums.getselecteditem().tostring())); resultset rs1=ps1.executequery(); string id = ""; while(rs1.next()) { id = rs1.getstring(1); } ps1.close(); for(object a:artists.getselectedvalueslist()) { ps = con.preparecall ("{call addsongartist(?, ?)}"); ps.setstring(1, id); ps.setstring(2, artistid.get(a.tostring())); ps.executeupdate(); ps.close(); } con.close(); } catch (exception e) {e.printstacktrace();} this.updatetable(); joptionpane.showmessagedialog(this, "success!\n"); } } catch (exception e) { joptionpane.showmessagedialog(this, "error!\n"+e.getmessage()); } }