?? deleteaction.java~2~
字號:
package informationsystem.gui;
import java.awt.event.*;
import informationsystem.gui.MainWindow;
public class DeleteAction
implements ActionListener {
private MainWindow window;
public DeleteAction(MainWindow window) {
this.window = window;
}
/**
* Invoked when an action occurs.
*
* @param e ActionEvent
* @todo Implement this java.awt.event.ActionListener method
*/
public void actionPerformed(ActionEvent e) {
try
{
String number =
if (rSet.next()==false) // 判斷數據庫中是否有要刪除的記錄,如沒有則顯示提示框
{
jTextField5.setText("");
jTextPane1.setText("數據庫中沒有您要刪除的學號!");
}
else
{
String sql2="delete from stu_info where 學號='"+jTextField5.getText()+"'";
statement.executeUpdate(sql2); // 刪除stu_info表中對應學號的數據記錄
// 清空信息框
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextPane1.setText("記錄已成功刪除!");
}
}
catch(SQLException ex) // 捕捉異常
{
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null)
{
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
catch(Exception ex )
{
ex.printStackTrace();
}
finally
{
try
{
if(statement != null)
{
statement.close(); // 關閉Statement接口實例
}
if(connection != null)
{
connection.close(); // 關閉Connection接口實例
}
}
catch (SQLException ex)
{
System.out.println("\nERROR:----- SQLException -----\n");
System.out.println("Message: " + ex.getMessage( ));
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -