📄 asstoprofesion2.java
字号:
/*
* Asstoprofesion2.java
*
* Created on 2007年11月24日, 下午12:46
*/
package javaapplication1;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author mis05
*/
public class Asstoprofesion2 extends javax.swing.JFrame {
/** Creates new form Asstoprofesion2 */
public Asstoprofesion2() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("\u4e13\u4e1a\u7f16\u53f7");
jButton1.setText("\u5220\u9664");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
delete(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(91, 91, 91)
.add(jLabel1)
.add(33, 33, 33)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 79, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(126, 126, 126)
.add(jButton1)))
.addContainerGap(149, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(97, 97, 97)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel1)
.add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(37, 37, 37)
.add(jButton1)
.addContainerGap(123, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void delete(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_delete
Statement sql;
try{
Conect conect = new Conect();
sql = conect.dbConn.createStatement();
String number = jTextField1.getText();
if( number.equals("") )
{
JOptionPane.showMessageDialog(null,"请输入需要删除的专业编号","错误",JOptionPane.ERROR_MESSAGE);
}
else
{
String output = null;
ResultSet rs = sql.executeQuery("select 专业名称 from 专业 where 专业编号 = '"+ number +"'" );
if( rs.next() )
{
output = "已删除专业编号:"+ number + " 专业名称:";
output += (String) rs.getObject(1);
int reg;
reg = sql.executeUpdate("delete from 专业 where 专业编号 = '"+ number +"'");
JOptionPane.showMessageDialog(null,output,"删除成功",JOptionPane.INFORMATION_MESSAGE);
}
else JOptionPane.showMessageDialog(null,"不存在此专业编号","错误",JOptionPane.ERROR_MESSAGE);
}
dispose();
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1); }// TODO add your handling code here:
}//GEN-LAST:event_delete
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Asstoprofesion2().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -