//step2 create  the connection object
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());
        }
    }
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");
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)));
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));
}