これがその場所かどうかはわかりませんが、アイデアがありません。以下は私のプログラムの更新コードです。単純ですが、何らかの理由で機能しません。
private void txt_updateActionPerformed(java.awt.event.ActionEvent evt) {
try{
String value1= txt_id.getText();
String value2= txt_title.getText();
String value3= txt_firstname.getText();
String value4= txt_lastname.getText();
String sql="update publishers set publisher_id='"value1"', publisher_title='"value2"', publisher_name='"value3"', publisher_lastname='"value4"' WHERE publisher_id='"value1"'";
pst=conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Updated");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
Update_table();
}
何がうまくいかないのかわからない。物事を変えてみましたが、役に立ちません。プログラム内で機能しますが、実際にデータベースを更新するわけではありません。だから私はプログラムを再起動しても何も変わらなかった
わかりました、成功せずに次のことも試しました。
private void txt_updateActionPerformed(java.awt.event.ActionEvent evt) {
try{
String value1= txt_id.getText();
String value2= txt_title.getText();
String value3= txt_firstname.getText();
String value4= txt_lastname.getText();
String sql="update publishers set publisher_id='" + value1 + "', publisher_title='" + value2 + "',publisher_name='" + value3 + "', publisher_lastname='" + value4 + "'WHERE publisher_id='" + value1 + "'";
pst=conn.prepareStatement(sql);
pst.execute();
conn.setAutoCommit(true);
JOptionPane.showMessageDialog(null, "Updated");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
Update_table();
}
そしてこれ
private void txt_updateActionPerformed(java.awt.event.ActionEvent evt) {
try{
String sql="update publishers set publisher_id=?, publisher_title=?, publisher_name=?, publisher_lastname=? WHERE publisher_id=?";
pst=conn.prepareStatement(sql);
pst.setString(1, txt_id.getText());
pst.setString(2, txt_title.getText());
pst.setString(3, txt_firstname.getText());
pst.setString(4, txt_lastname.getText());
pst.setString(5, txt_id.getText());
pst.execute();
conn.setAutoCommit(true);
JOptionPane.showMessageDialog(null, "Updated");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
Update_table();
}
update_tableは次のとおりです
private void Update_table(){
try{
String sql="select publisher_id, publisher_title, publisher_name, publisher_lastname from publishers";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
Table_Publishers.setModel(DbUtils.resultSetToTableModel(rs));
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
}