📄 deletedata.java
字号:
/**
* public static final String DELETEATEACHER = "delete from EBook where ebook_id = ?";
*/
/**
* @author Linden
* @date 下午09:10:542007-10-20
*/
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
import javax.swing.JOptionPane;
class DeleteData extends Frame implements ActionListener {
Label label;
TextField tf;
Button button;
public static final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=EBook";
public static final String user = "sa"; // sqlserver 连接
public static final String password = "123456";
static Connection conn = null;
static PreparedStatement pstmt = null;
static ResultSet rs = null;
DeleteData() {
super("删除书目");
label = new Label("请输入要删除书目的书号");
tf = new TextField(20);
button = new Button("删除");
button.addActionListener(this);
setLayout(new FlowLayout());
add(label);
add(tf);
add(button);
setBounds(120, 120, 300, 300);
setVisible(true);
validate();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException e1) {
System.out.println("没能发现驱动程序!");
}
try {
conn = DriverManager.getConnection(url, user, password);
} catch (SQLException e1) {
// TODO Auto-generated catch block
System.out.println("没能发现驱数据库或者用户名密码错误!");
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if (e.getSource() == button) {
try {
int bookno = Integer.parseInt(tf.getText());
pstmt = conn
.prepareStatement("delete from EBook where ebook_id = ?");
pstmt.setInt(1, bookno);
pstmt.executeUpdate();
conn.close();
pstmt.close();
JOptionPane.showMessageDialog(null, "成功删除数据库!");
} catch (SQLException e2) {
JOptionPane.showMessageDialog(null, "出错,不能删除!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -