114 JButton btnInsert new JButton Insert btnInsert addAction Listener new Action
ID: 3848207 • Letter: 1
Question
114 JButton btnInsert new JButton Insert btnInsert addAction Listener new Action Listener 115e public void actionPerformed ActionEvent e) 1 16 17 try 18 String query Insert INTO DVD (Title, Year, Runtime) values C?,?, Prepared Statement pStatement conn., Statement query) .prepare 119 pStatement.setStringC1, textTitle.getTextO) 120 21 p Statement setString textYear. getTextO); 22 Double time Double parse DoubleCtextRun time getTexto) pStatement.setDoubleC3, r time 124 pStatement execute JOptionPane. showMessageDialogCnull, Record Inserted into DVD table") 25 26 27 catch CException e2) 28 JOptionPane. null Error inserting record") 129 30 31 132 133 134 set Bounds(6, 243, 117, 29); 135 btn Insert frame getContent PaneC) addCbtnInsert); 136 137 JButton btnUpdate new JButtonC"Update") 138 btnUpdate addAction Listener new Action Listener CD 1 139 public void actionPerformed ActionEvent e) 1 40 41 42 43 btnUpdate 243, 117, 29) 44 frame get ContentPane() addC btn Update) 45 46 Button btnDelete new JButton "Delete 47 btnDelete. setBounds(252, 243, 117, 29) L48 frame getContent Panec). add btn Lete); 49 JScrollPane scroll Pane 1 new JScrollPaneO; 50 51 scroll Pane 1 set Bounds (189, 71, 219, 160) frame getContent PaneO. addC 152 scroll Pane 1 Source DesignExplanation / Answer
For Update:
String updateTableSQL = "UPDATE DVD SET Year = ? SET RunTime = ? WHERE Title = ?";
PreparedStatement preparedStatement = dbConnection.prepareStatement(updateTableSQL);
preparedStatement.setString(1, textTitle.getText());
preparedStatement.setDouble(2,textYear.getText());
Double rtime=Double.parseDouble(textRunTime.getText());
try{
preparedStatement .executeUpdate();}
catch(SQLException sle){
// process exception here
sle.printStackTrace();
} catch(Exception e){
// process exception here
e.printStackTrace();
}
JOptionPane.showMessageDialog(null,"Updated Record");
For Delete:
String deleteSQL = "DELETE DVD WHERE Title = ?";
PreparedStatement preparedStatement = dbConnection.prepareStatement(deleteSQL);
preparedStatement.setString(1, textTitle.getText());
// execute delete SQL stetement
try{
preparedStatement.executeUpdate();}
catch(SQLException sle){
// process exception here
sle.printStackTrace();
} catch(Exception e){
// process exception here
e.printStackTrace();
}
JOptionPane.showMessageDialog(null,"Deleted Record");
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.