java用户密码修改_java更改管理员用户名和密码

这是一个使用Java实现的用户登录系统,包括用户界面和数据库连接。通过Access数据库存储用户信息,用户登录后根据权限展示不同的操作选项,如追加、删除和查询。管理员可以进行更高级别的操作。
摘要由CSDN通过智能技术生成

展开全部

分三个包,自己建个包,导进去就ok了,数据库是access的。package登录e69da5e6ba903231313335323631343130323136353331333363373835;importjava.awt.EventQueue;publicclassCilent{privateJFrameframe;privateJTextFieldtextField;privateJPasswordFieldpasswordField;/***Launchtheapplication.*/publicstaticvoidmain(String[]args){EventQueue.invokeLater(newRunnable(){publicvoidrun(){try{Cilentwindow=newCilent();window.frame.setVisible(true);}catch(Exceptione){e.printStackTrace();}}});}/***Createtheapplication.*/publicCilent(){initialize();}/***Initializethecontentsoftheframe.*/privatevoidinitialize(){frame=newJFrame();frame.setTitle("登陆界面");frame.setBounds(100,100,450,300);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.getContentPane().setLayout(null);frame.setResizable(false);JLabellblNewLabel=newJLabel("用户名");lblNewLabel.setBounds(38,43,80,34);frame.getContentPane().add(lblNewLabel);textField=newJTextField();textField.setBounds(155,42,227,37);frame.getContentPane().add(textField);textField.setColumns(10);JLabellabel=newJLabel("密 码");label.setBounds(38,115,80,34);frame.getContentPane().add(label);passwordField=newJPasswordField();passwordField.setBounds(155,115,227,37);frame.getContentPane().add(passwordField);JButtonbtnNewButton=newJButton("登 录");btnNewButton.setBounds(60,187,115,34);frame.getContentPane().add(btnNewButton);btnNewButton.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEventarg0){//TODOAuto-generatedmethodstubUserCheckUC=newUserCheck(textField.getText(),String.valueOf(passwordField.getPassword()));if(UC.getI()!=0)//有此用户{frame.setVisible(false);}else{textField.setText("");passwordField.setText("");}}});JButtonbutton=newJButton("取 消");button.setBounds(242,187,115,34);frame.getContentPane().add(button);button.addActionListener(newActionListener(){@OverridepublicvoidactionPerformed(ActionEventarg0){//TODOAuto-generatedmethodstubtextField.setText("");passwordField.setText("");}});}}/*****************************************************************/package登录;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;import操作处理.UsersCL;/**@author20111024*检测登录的用户在数据库中有无,若没有,则提示没有此用户,*若有,则判断级别:普通用户还是管理员。*/publicclassUserCheck{privateinti=0;//用户级别:0不是用户、1是管理员、2是普通用户UserCheck(Stringname,Stringpassword){Stringjdriver="sun.jdbc.odbc.JdbcOdbcDriver";StringconnectDB="jdbc:odbc:Students";Statementstmt=null;ResultSetrs=null;Connectioncon=null;try{Class.forName(jdriver);con=DriverManager.getConnection(connectDB);stmt=con.createStatement();Stringquery="select*fromuserswherename='"+name+"'andpasswd='"+password+"'";rs=stmt.executeQuery(query);if(rs.next()){//数据库中有此用户,访问成功i=Integer.parseInt(rs.getString(3));UsersCLUL=newUsersCL(i);}else{i=0;//没有用户是默认是0级}}catch(ClassNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(SQLExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}publicintgetI(){returni;}}/********************************************************************************************/package操作处理;importjava.awt.EventQueue;publicclassUsersCLimplementsActionListener{privateJFrameframe;privateJTextFieldtextField;privateJTextFieldtextField_1;privateJTextFieldtextField_2;privateJTextFieldtextField_3;privateinti=0;privateJLabellabel_3;privateJTextFieldtextField_4;publicUsersCL(inti){this.i=i;frame=newJFrame();frame.setTitle("用户处理界面");frame.setBounds(100,100,450,300);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.getContentPane().setLayout(null);frame.setResizable(false);frame.setVisible(true);JLabellblNewLabel=newJLabel("学 号");lblNewLabel.setBounds(24,32,74,29);frame.getContentPane().add(lblNewLabel);JLabellabel=newJLabel("姓 名");label.setBounds(24,71,74,29);frame.getContentPane().add(label);JLabellabel_1=newJLabel("年 龄");label_1.setBounds(24,110,74,29);frame.getContentPane().add(label_1);label_3=newJLabel("性 别");label_3.setBounds(24,149,74,29);frame.getContentPane().add(label_3);JLabellabel_2=newJLabel("状 态");label_2.setBounds(24,195,74,29);frame.getContentPane().add(label_2);textField=newJTextField();textField.setBounds(101,34,113,25);frame.getContentPane().add(textField);textField.setColumns(10);textField_1=newJTextField();textField_1.setColumns(10);textField_1.setBounds(101,73,113,25);frame.getContentPane().add(textField_1);textField_2=newJTextField();textField_2.setColumns(10);textField_2.setBounds(101,112,113,25);frame.getContentPane().add(textField_2);textField_3=newJTextField();textField_3.setEditable(false);textField_3.setColumns(10);textField_3.setBounds(101,199,288,25);frame.getContentPane().add(textField_3);textField_4=newJTextField();textField_4.setColumns(10);textField_4.setBounds(101,149,113,25);frame.getContentPane().add(textField_4);if(1==i){JButtonbtnNewButton=newJButton("追 加");btnNewButton.setBounds(276,41,113,29);frame.getContentPane().add(btnNewButton);btnNewButton.addActionListener(this);btnNewButton.setActionCommand("追加");JButtonbutton_1=newJButton("删 除");button_1.setBounds(276,145,113,29);frame.getContentPane().add(button_1);button_1.addActionListener(this);button_1.setActionCommand("删除");}JButtonbutton=newJButton("查 询");button.setBounds(276,91,113,29);frame.getContentPane().add(button);button.addActionListener(this);button.setActionCommand("查询");}@OverridepublicvoidactionPerformed(ActionEvente){//TODOAuto-generatedmethodstubStringname,age,sex,query=null;intnum,age1,count=0;num=Integer.parseInt(textField.getText());name=textField_1.getText();age1=Integer.parseInt(textField_2.getText());sex=textField_4.getText();if(e.getActionCommand().equals("追加")){query="insertintostudentsvalues("+num+","+"'"+name+"',"+age1+",'"+sex+"');";count=1;}elseif(e.getActionCommand().equals("查询")){query="select*fromstudentswhereXSB="+num+";";count=2;}elseif(e.getActionCommand().equals("删除")){query="deletefromstudentswhereXSB="+num+"andname="+"'"+name+"'";count=3;}Statementstmt=null;ResultSetrs=null;Connectioncon=null;Stringjdriver="sun.jdbc.odbc.JdbcOdbcDriver";StringconnectDB="jdbc:odbc:Students";Stringquery1=null;try{Class.forName(jdriver);con=DriverManager.getConnection(connectDB);stmt=con.createStatement();if(count==1){query1="select*fromstudentswhereXSB="+num+";";rs=stmt.executeQuery(query1);if(rs.next())textField_3.setText("已经由此记录,不能追加!");else{stmt.executeUpdate(query);textField_3.setText("已经追加完成!");}}elseif(2==count){stmt.executeQuery(query);rs=stmt.executeQuery(query);if(rs.next()){textField_3.setText("已查找到此记录!");}else{textField_3.setText("没有此记录,可以追加!");}}elseif(3==count){query1="select*fromstudentswhereXSB="+num+"andname="+"'"+name+"'";rs=stmt.executeQuery(query1);if(rs.next()){stmt.executeUpdate(query);textField_3.setText("已删除此记录!");}elsetextField_3.setText("无此记录!");}}catch(ClassNotFoundExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}catch(SQLExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}finally{//关闭资源if(stmt!=null){try{stmt.close();}catch(Exceptione2){//TODO:handleexception}stmt=null;}if(con!=null){try{con.close();}catch(Exceptione2){//TODO:handleexception}con=null;}}}}

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值