一个球员管理系统

源代码在线查看: modifypassword.java

软件大小: 849 K
上传用户: zjf646
关键词: 管理系统
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*
				 * modifypassword.java
				 */
				
				package playermanager;
				import java.sql.*;
				import javax.swing.JOptionPane;
				
				public class modifypassword extends javax.swing.JFrame {
				    
				    /** Creates new form modifypassword */
				    MainJFrame MF=new MainJFrame();
				    public modifypassword() {
				        initComponents();
				    }
				    
				    public void validID() {
				    
				      String str1, str2,str3,str4;
				      str1 = jTextField1.getText();
				      str2 = jPasswordField1.getText();
				      str3 = jPasswordField2.getText();
				      
				      if(str1.length()==0||str2.length()==0||str3.length()==0)
				        JOptionPane.showMessageDialog(this,"请添加完整信息!");
				      else{
				     
				          try{
				     
				      String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
				      Driver driver = (Driver) Class.forName(driverName).newInstance();
				      //连接的数据库是名为“data“的数据库
				      //登录名是”sa“密码是“123”
				      Connection con = DriverManager.getConnection(
				          "jdbc:sqlserver://127.0.0.1:1433;", "sa", "123");
				      con.setCatalog("data"); //数据库名称
				      //执行动态的sql语句
				      PreparedStatement pstmt = con.prepareStatement("select name ,password from usernp where name=?");
				      //将用户的名字添加到具体的sql语句中
				       pstmt.setString(1, str1);
				      //使用ResultSet中的方法executeQuery()来完成sql语句的执行
				      ResultSet res = pstmt.executeQuery();
				    
				     
				    if (!res.next())  {
				        JOptionPane.showMessageDialog(this, "用户名错误,请重新输入!", "错误提示",
				                                      JOptionPane.ERROR_MESSAGE);
				      }else {
				                 if(str2.equals(str3)){
				                String str = "update usernp set password='"+str2+"' where name='" + str1 + "'";
				                PreparedStatement ps = con.prepareStatement(str);
				                ps.executeUpdate();
				                ps.close();
				               JOptionPane.showMessageDialog(this,"修改成功!");
				                 clearForm();
				                
				               
				                 } else{
				                     JOptionPane.showMessageDialog(this, "新密码错误,请重新输入!", "错误提示",
				                                      JOptionPane.ERROR_MESSAGE);    
				                      }
				             }
				      
				       pstmt.close();
				      
				       con.close();
				    }catch (InstantiationException e) {
				      System.out.println(e.getMessage());
				    }catch (IllegalAccessException e) {
				      System.out.println(e.getMessage());
				    }catch (ClassNotFoundException e) {
				      System.out.println(e.getMessage());
				    }catch (SQLException edd) {
				      edd.printStackTrace() ;
				      System.out.println(edd.getMessage());
				        }
				  }
				}
				     private void clearForm(){
				    jTextField1.setText("");
				    jPasswordField1.setText("");
				    jPasswordField2.setText("");
				    
				    jTextField1.requestFocus();
				      }
				    
				    /** 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.
				     */
				    // //GEN-BEGIN:initComponents
				    private void initComponents() {
				        jLabel1 = new javax.swing.JLabel();
				        jLabel2 = new javax.swing.JLabel();
				        jLabel3 = new javax.swing.JLabel();
				        jTextField1 = new javax.swing.JTextField();
				        jPasswordField1 = new javax.swing.JPasswordField();
				        jPasswordField2 = new javax.swing.JPasswordField();
				        jButton1 = new javax.swing.JButton();
				        jButton2 = new javax.swing.JButton();
				        jButton3 = new javax.swing.JButton();
				
				        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
				        setTitle("\u4fee\u6539\u7ba1\u7406\u5458\u5bc6\u7801 ");
				        setResizable(false);
				        jLabel1.setText("\u8bf7\u8f93\u5165\u7528\u6237\u540d\uff1a");
				
				        jLabel2.setText("\u8bf7\u8f93\u5165\u65b0\u5bc6\u7801\uff1a");
				
				        jLabel3.setText("\u786e\u8ba4  \u65b0\u5bc6\u7801\uff1a");
				
				        jButton1.setText("\u786e\u8ba4\u4fee\u6539");
				        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				            public void mouseClicked(java.awt.event.MouseEvent evt) {
				                jButton1MouseClicked(evt);
				            }
				        });
				
				        jButton2.setText("\u53d6\u6d88");
				        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
				            public void mouseClicked(java.awt.event.MouseEvent evt) {
				                jButton2MouseClicked(evt);
				            }
				        });
				
				        jButton3.setText("\u6e05\u7a7a");
				        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
				            public void mouseClicked(java.awt.event.MouseEvent evt) {
				                jButton3MouseClicked(evt);
				            }
				        });
				
				        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
				        getContentPane().setLayout(layout);
				        layout.setHorizontalGroup(
				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				            .addGroup(layout.createSequentialGroup()
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
				                    .addGroup(layout.createSequentialGroup()
				                        .addGap(31, 31, 31)
				                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                            .addComponent(jLabel1)
				                            .addComponent(jLabel2)
				                            .addComponent(jLabel3))
				                        .addGap(52, 52, 52))
				                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
				                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				                        .addComponent(jButton1)
				                        .addGap(42, 42, 42)))
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				                    .addGroup(layout.createSequentialGroup()
				                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
				                        .addGap(44, 44, 44)
				                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
				                    .addGroup(layout.createSequentialGroup()
				                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
				                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
				                            .addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING)
				                            .addComponent(jPasswordField1, javax.swing.GroupLayout.Alignment.LEADING)
				                            .addComponent(jPasswordField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE))))
				                .addContainerGap(48, Short.MAX_VALUE))
				        );
				        layout.setVerticalGroup(
				            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				            .addGroup(layout.createSequentialGroup()
				                .addGap(39, 39, 39)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                    .addComponent(jLabel1)
				                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				                .addGap(39, 39, 39)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                    .addComponent(jLabel2)
				                    .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				                .addGap(47, 47, 47)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                    .addComponent(jLabel3)
				                    .addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
				                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
				                    .addComponent(jButton3)
				                    .addComponent(jButton1)
				                    .addComponent(jButton2))
				                .addGap(39, 39, 39))
				        );
				        pack();
				    }// //GEN-END:initComponents
				
				    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
				// TODO 将在此处添加您的处理代码:
				        clearForm();
				    }//GEN-LAST:event_jButton3MouseClicked
				
				    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
				// TODO 将在此处添加您的处理代码:
				        validID();
				    }//GEN-LAST:event_jButton1MouseClicked
				
				    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
				// TODO 将在此处添加您的处理代码:
				               MF.setVisible(true);
				               this.setVisible(false);
				    }//GEN-LAST:event_jButton2MouseClicked
				    
				    /**
				     * @param args the command line arguments
				     */
				    public static void main(String args[]) {
				        java.awt.EventQueue.invokeLater(new Runnable() {
				            public void run() {
				                new modifypassword().setVisible(true);
				            }
				        });
				    }
				    
				    // 变量声明 - 不进行修改//GEN-BEGIN:variables
				    private javax.swing.JButton jButton1;
				    private javax.swing.JButton jButton2;
				    private javax.swing.JButton jButton3;
				    private javax.swing.JLabel jLabel1;
				    private javax.swing.JLabel jLabel2;
				    private javax.swing.JLabel jLabel3;
				    private javax.swing.JPasswordField jPasswordField1;
				    private javax.swing.JPasswordField jPasswordField2;
				    private javax.swing.JTextField jTextField1;
				    // 变量声明结束//GEN-END:variables
				    
				}
							

相关资源