Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the code I have so far and this has to be added. I also have my own data

ID: 3847519 • Letter: T

Question

This is the code I have so far and this has to be added. I also have my own database code written

1) Write the code for the 'Update' button. When the user clicks on a ROW in the JTable where the data is displayed, the data from that row should be displayed in the Text boxes on the left. The user will then make changes in the Textboxes and click the 'Update' button to update the DVD Table. Clicking the 'Load Table' button should display the updated table data.

2) Write the code for the 'Delete' button. When the user clicks on a ROW in the JTable where the data is displayed, the data from that row should be displayed in the Text boxes on the left. The user will then click the 'Delete' button to delete the clicked row from the DVD Table. Clicking the 'Load Table' button should display the table data with the row deleted.

HINT:

int row =table.getSlectedRow();
String title = table.getModel().getValueAt(row,1)).toString();

Connect java DVDManager,java 1e import java-awt.Event Queue 3 import javax.swing.JFrame 4 import javax.swing.JButton 5 import javax.swing.JLabel 6 import javax.swing. J0ptionPane 7 import javax.swing. JTextField 9 import net .proteanit.sql .Dbut i Ls; 10 11 import javax.swing. JTable 12 import javax.swing. JScrol Pane 13 import java.awt.event.ActionListener 14 import java.sql.Connection 15 import java.sgl Prepared Statement. 16 import java.sql.ResultSet 17 import java awt.event.ActionEvent. 18 19 public class DWDManager 1 20 21 private JFrame frame 22 private JTextField text Title 23 private JTextField text Year 24 private JTextField textRuntime 25 private JTable table 26 27 Launch the application. 28 29 30 public static void main String[] args Event Queue invokeLater(new Runnable() 31 public void run A 32 try 33 DVD Manager window new DVDManager 34 window frame .setVisible true 35 catch (Exception e) 36 e printStackTrace 37 38 39 40 41 42

Explanation / Answer

del.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){

String val=txt4.getText();
Connection connection = null;
String connn = "jdbc:mysql://localhost:3306/";
String database = "AkshayBisht"; // Database name
String drivers = "com.mysql.jdbc.drivers"; // Driver address
String id = "aaki"; // Connecting to Database with ID and Password
String pswd = "aaki";
try{
Class.forName(drivers);
connection = DriverManager.getConnection(connn+database, id, pswd);
PreparedStatement ps=connection.prepareStatement("DELETE FROM employee WHERE id = ?"); // Defining where to delete the values
ps.setString(1,val);
ps.executeUpdate();
JOptionPane.showMessageDialog(jp3,"Infromation deleted successfully.........");
connection.close();
}
catch(Exception exp3)
{
JOptionPane.showMessageDialog(jp3,"Problem in Deleting Record...........");
}
}
});


edit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){

String value=txt6.getText();
Connection connection = null;
String connn = "jdbc:mysql://localhost:3306/";
String database = "AkshayBisht";
String drivers = "com.mysql.jdbc.drivers";
String id = "aaki";
String pswd = "aaki";
try{
Class.forName(drivers);
connection = DriverManager.getConnection(connn+database, id, pswd);
PreparedStatement ps=connection.prepareStatement("select * from employee where id=?"); // Defining where to edit the values
ps.setString(1,value);
ResultSet res=ps.executeQuery();
res.next();
txt6.setText(Integer.toString(res.getInt(1)));
txt7.setText(res.getString(2));
txt8.setText(res.getString(3));
txt9.setText(Integer.toString(res.getInt(4)));
connection.close();
}
catch(Exception e)
{
JOptionPane.showMessageDialog(jp2,"Unable to Edit Data");
}
}
});
edit1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
Connection connection = null;
String connn = "jdbc:mysql://localhost:3306/";
String database = "AkshayBisht"; // Connecting to a particular database
String drivers = "com.mysql.jdbc.drivers";
String id = "aaki"; // Connecting to Database with ID and Password
String pswd = "aaki";
try
{
int x=JOptionPane.showConfirmDialog(jp2,"Edit Confirmed. All Information editted successfully.......");
if(x==0){
try{
String val=txt6.getText();
String val1=txt7.getText();
String val2=txt8.getText();
String val3=txt9.getText();

Class.forName(drivers);
connection = DriverManager.getConnection(connn+database, id, pswd);;
Statement ps=connection.createStatement();
ps.executeUpdate("update employee set emp_name='"+val1+"', emp_address='"+val2+"',
salary='"+val3+"' where emp_id='"+val+"'");
JOptionPane.showMessageDialog(jp2,"Updated successfully........................");
connection.close();
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(jp2,"Problem in Updating. Fix it to carry on");
}
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(jp2,"Error in the Program.....");
}
}
});

Please rate the answer if it helped... Thankyou

Hope it helpsss.......

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote