




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、項目名稱 :用戶管理系統開發環境 : 1. JDK 6.0 2. Eclipse 3.3或MyEclipse6.03. Oracle 10g軟件功能 :1. 注冊功能: 用戶可以注冊成本軟件的用戶。(注:權限是 普通用戶)如下圖:2. 登錄功能: 用戶輸入用戶名和密碼。斷用戶是否存在存在:提取用戶的權限 權限如果是:管理員的話則顯示如下圖權限如果是:普通用戶的話則顯示如下圖:3. 普通用戶的修改功能普通用戶可以修改自己的name ,pass ,mail不能修改權限和ID。運行效果如下圖:4. 普通用戶的查詢功能普通用戶可以查詢自己的詳細信息運行效果如下圖:5. 管理員的添加功能管理員的添加和普
2、通用戶的注冊一樣。Id自動分配。權限是普通用戶:運行效果如圖:6. 管理員的修改功能:管理員可以修改任何人的信息。(注:可以把普通用戶修改成管理員)根據id 修改某個用戶信息運行效果如圖:7. 管理員的查詢功能:管理員可以有三個查詢方式:運行效果如圖:1. 全部查詢:運行效果如圖:2. 根據id查詢某一個用戶:運行效果如圖:3. 根據用戶名查詢:支持模糊查詢運行效果如圖:8. 管理員的刪除功能:運行效果如圖:工作流程圖:用戶注冊普通用戶No根據NAME查詢 查詢全部用戶根據ID查詢 添加用戶 刪除用戶 修改用戶 查詢用戶 查詢個人信息 修改個人信息管理員 管理員 普通用戶判斷用戶權限Yes判斷
3、用戶是否存存在 用戶登錄import java.sql.Connection;import java.sql.SQLException;import java.sql.Statement;public class administrator final static connection connect= new connection();final static Connection conn = connect.connectDbByOci();String selectAdminTable = "select * from admintable"String admi
4、nTable = "create table admintable(username varchar(20)"String selectAdmin = "select * from admintable where username='admin'"String insertDefaultAdmin = "insert into admintable(username) values('admin')"String selectAdminOnUsertable = "select * from
5、 usertable where username='admin'"String insertAdminToUsertable = "insert into usertable(username,passwd,usermail) values('admin','1234','admin1234')"public administrator()try Statement stmt = conn.createStatement();/stmt.executeUpdate(selectAdmin);stmt
6、.executeUpdate(selectAdminTable);/查看管理員的表是否存在if (stmt!=null)stmt.close();catch(SQLException e)tryStatement stmt = conn.createStatement();/stmt.executeUpdate(defaultAdmministator);stmt.executeUpdate(adminTable);/創建管理員表if (stmt!=null)stmt.close();catch (SQLException a)a.printStackTrace();try Statement
7、 stmt = conn.createStatement();if(stmt.executeUpdate(selectAdmin)=0)/查看有沒有admin這個管理員賬號stmt.executeUpdate(insertDefaultAdmin);if(stmt.executeUpdate(selectAdminOnUsertable)=0)stmt.executeUpdate(insertAdminToUsertable);if (stmt!=null)stmt.close();catch(SQLException e)e.printStackTrace();public administ
8、rator(String username,String passwd,String usermail)/可提供創建管理員的方法String insertAdmintable = "insert into admintable(username) values('"+username+"')"String selectAdminuser = "select * from usertable where username='"+username+"'"String insertAdmi
9、nUser = "insert into usertable(username,passwd,usermail) values('"+username+"','"+passwd+"','"+usermail+"')"tryStatement stmt = conn.createStatement();stmt.executeUpdate(insertAdmintable);if(stmt.executeUpdate(selectAdminuser)=0)stmt.ex
10、ecuteUpdate(insertAdminUser);elseSystem.out.println("更新失??!請換個管理員用戶名");if (stmt!=null)stmt.close();catch (SQLException c)c.printStackTrace();import java.sql.*;public class connection final static String sDBDriver = "oracle.jdbc.driver.OracleDriver"final static String sConnStr = &q
11、uot;jdbc:oracle:oci8:system/managerORCLLGG"/oci方法/final static String sConnStr = "jdbc:oracle:thin:localhost:1521:ORCLLGG"/thin方法連接數據庫public connection()public Connection connectDbByOci()Connection conn=null;tryClass.forName(sDBDriver);/conn = DriverManager.getConnection(sConnStr,&quo
12、t;sys as sysdba","oracle");conn = DriverManager.getConnection(sConnStr);catch (Exception e)System.out.println("error:"+e.getMessage();return conn;import java.sql.Connection;import java.sql.SQLException;import java.sql.Statement;/import java.util.Scanner;public class CreateUs
13、erTable final static connection connect= new connection();final static Connection conn = connect.connectDbByOci();String createUserinfo = "create table usertable(id number,username varchar(20),passwd varchar(20),usermail varchar(20)"/存放用戶信息表String selectUserTable = "select * from user
14、table"/定義觸發器String idSeq = "create sequence user_id start with 1 increment by 1 nomaxvalue"String selectSeq = "select sequence_name from all_sequences where sequence_name='USER_ID'"String idTrigger = "create or replace trigger id_trg before insert on usertable f
15、or each row begin if inserting then select user_id.nextval into :new.id from dual;end if;end;"public CreateUserTable()try Statement stmt = conn.createStatement();/*if (stmt.executeUpdate(selectMailTable) != 0)/存放用戶郵箱的表selectMailTablestmt.executeUpdate(query);*/stmt.executeUpdate(selectUserTable
16、);/查看是否有這個用戶表if (stmt!=null)stmt.close();catch(SQLException e)tryStatement stmt = conn.createStatement();stmt.executeUpdate(createUserinfo);/創建用戶表if (stmt!=null)stmt.close();catch (SQLException a)a.printStackTrace();/System.out.println("ssss");try /為用戶表中的id列自動建值,默認管理員的id是1Statement stmt =
17、conn.createStatement();if(stmt.executeUpdate(selectSeq)=0)stmt.executeUpdate(idSeq);/序列/stmt.executeUpdate(idTrigger);/觸發器/stmt.executeUpdate(idSeq);/序列stmt.executeUpdate(idTrigger);/觸發器catch(SQLException e)e.printStackTrace();public class Main public static void main (String args)new CreateUserTabl
18、e();new administrator();new Outline().welcome();import java.util.Scanner;import java.sql.*;public class Outline final static connection connect= new connection();final static Connection conn = connect.connectDbByOci();void welcome()Scanner sc = new Scanner(System.in);System.out.println("歡迎使用neu
19、soft的用戶管理系統");System.out.println("=");System.out.println("用戶登錄-1");System.out.println("用戶注冊-2");System.out.println("退出程序-3");int InputNu=sc.nextInt();switch (InputNu)case 1:log();break;case 2:regedit();break;case 3:quit();break;default: System.out.println
20、("請輸入正確的號碼:1|2|3");void log()Scanner sc = new Scanner(System.in);System.out.println("用戶登錄界面");System.out.println("=");System.out.println("請輸入你的用戶名");String oldname=sc.next();System.out.println("請輸入你的密碼");String oldpasswd=sc.next();String authtication
21、 = "select * from usertable where username='"+oldname+"' and passwd='"+oldpasswd+"'"String adminAuthtication = "select * from admintable where username='"+oldname+"'"int adminId = 0;/判斷是否是管理員try Statement stmt = conn.createSta
22、tement();if (stmt.executeUpdate(authtication) =0)System.out.println("用戶名或密碼錯誤,請重新登錄");log();else System.out.println("登錄成功");adminId=stmt.executeUpdate(adminAuthtication);/將受影響的語句的行數返回給adminidif (adminId=0)System.out.println(oldname+"你好! "+"你的權限是:管理員");System.o
23、ut.println("修改自己的信息-1");System.out.println("查詢自己的信息-2");System.out.println("退出程序-3");int number=sc.nextInt();switch (number)case 1:String userinfo = "select * from usertable where username='"+oldname+"'"System.out.println("你現在的信息是:"
24、);try ResultSet rs = stmt.executeQuery(userinfo);while(rs.next()System.out.println("用戶名"+rs.getString(2)+" 密碼"+rs.getString(3)+" 郵箱"+rs.getString(4);/取查詢的結果System.out.println("請輸入要修改的姓名");String newname=sc.next();System.out.println("請輸入要修改的密碼");Strin
25、g newpasswd=sc.next();System.out.println("請輸入要修改的郵箱");String newmail=sc.next();String alterUserinfo = "update usertable set username='"+newname+"',passwd='"+newpasswd+"',usermail='"+newmail+"' where username='"+oldname+&qu
26、ot;'"if(stmt.executeUpdate(alterUserinfo)!=0)System.out.println("修改成功");elseSystem.out.println("修改失敗");if(rs!=null)rs.close();if (stmt!=null)stmt.close();catch(SQLException e)e.printStackTrace();break;case 2:String userinfo = "select * from usertable where username=
27、'"+oldname+"'"System.out.println("你現在的信息是:");try ResultSet rs = stmt.executeQuery(userinfo);while(rs.next()System.out.println("用戶名"+rs.getString(2)+" 密碼"+rs.getString(3)+" 郵箱"+rs.getString(4);if (stmt!=null)stmt.close();catch(SQLExceptio
28、n e)e.printStackTrace();break;case 3:quit();break;default: System.out.println("請輸入正確的號碼:1|2|3");elseSystem.out.println(oldname+"你好! "+"你的權限是:普通用戶");System.out.println("添加用戶-1");System.out.println("刪除用戶-2");System.out.println("修改用戶-3");Syste
29、m.out.println("查詢用戶-4");System.out.println("程序退出-5");int number=sc.nextInt();switch(number)case 1:/添加用戶System.out.println("請輸入用戶名");String name=sc.next();System.out.println("請輸入密碼");String passwd=sc.next();System.out.println("請輸入郵箱");String mail=sc.n
30、ext();String insertUserinfo = "insert into usertable(username,passwd,usermail) values('"+name+"','"+passwd+"','"+mail+"')"String adminauthtication = "select * from usertable where username='"+name+"'"try if(s
31、tmt.executeUpdate(adminauthtication)=0)stmt.executeUpdate(insertUserinfo);System.out.println("用戶添加成功");elseSystem.out.println("添加失敗,用戶已存在,請換個用戶名");if (stmt!=null)stmt.close();catch(SQLException e)e.printStackTrace();break;case 2:/刪除用戶System.out.println("請輸入要刪除的用戶ID號");i
32、nt id=sc.nextInt();String deluser="delete from usertable where id='"+id+"'"try stmt.executeUpdate(deluser);System.out.println("刪除用戶成功");catch (SQLException e)e.printStackTrace();break;case 3:/修改用戶System.out.println("請輸入要修改的用戶ID");int id=sc.nextInt();Sy
33、stem.out.println("請輸入要修改的用戶名");String newname=sc.next();System.out.println("請輸入要修改的密碼");String newpasswd=sc.next();System.out.println("請輸入要修改的郵箱");String newmail=sc.next();System.out.println("請輸入要修改的用戶權限(admin/normal)");String newpower=sc.next();String alterus
34、erinfo="update usertable set username='"+newname+"',passwd='"+newpasswd+"',usermail='"+newmail+"' where id='"+id+"'"String insertadmin="insert into admintable(username) values('"+newname+"')"
35、;try stmt.executeUpdate(alteruserinfo);System.out.println(newpower);if(newpower.equals("admin")/字符常量的比較stmt.executeUpdate(insertadmin);System.out.println("普通用戶變為管理員用戶");System.out.println("普通用戶修改成功");catch(SQLException e)e.printStackTrace();break;case 4:/查詢用戶System.out.
36、println("查詢全部用戶-1");System.out.println("根據ID查詢用戶-2");System.out.println("根據姓名查詢用戶-3");int snumber=sc.nextInt();if(snumber=1)/全部String allinfo="select * from usertable"try ResultSet rs = stmt.executeQuery(allinfo);while(rs.next()System.out.println("ID:&quo
37、t;+rs.getString(1)+" 用戶名:"+rs.getString(2)+" 密碼:"+rs.getString(3)+" 郵箱:"+rs.getString(4);/可直接輸出4列的全部信息catch (SQLException e)e.printStackTrace();if(snumber=2)/IDSystem.out.println("請輸入要查詢的ID");int idnumber=sc.nextInt();String idinfo= "select * from usertab
38、le where id='"+idnumber+"'"try ResultSet rs = stmt.executeQuery(idinfo);while(rs.next()System.out.println("ID:"+rs.getString(1)+" 用戶名:"+rs.getString(2)+" 密碼:"+rs.getString(3)+" 郵箱:"+rs.getString(4);/可直接輸出4列的全部信息catch(SQLException e)e.printStackTrace();if(snumber=3)/姓名System.out.println("請輸入要查詢的用戶名(支持模糊查詢)");String name=sc.next();String nameinfo= "select * from usertable where username like '%"+name+"%'"try ResultSet rs = stmt.executeQuery(nameinfo);while(rs.next()System.out.println(&qu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 延邊大學《環境流體力學》2023-2024學年第二學期期末試卷
- 江蘇省無錫市玉祁初級中學2025屆初三下學期中考試生物試題含解析
- 湖南省長沙市2025屆高三下學期返校英語試題含解析
- 遼寧經濟職業技術學院《涉外禮儀》2023-2024學年第二學期期末試卷
- 溫州醫科大學《電影批評》2023-2024學年第一學期期末試卷
- 食品經營許可證辦理流程
- 2025設備租賃合同糾紛民事訴狀起訴書
- 2025年招標師考試合同管理模擬題
- 2025塑料管材購銷合同范本
- 給藥治療與護理
- 綜合執法改革試題及答案
- 2024年泉州實驗中學初一新生入學考試數學試卷
- 人工智能在航班調度中的未來應用探討
- 內蒙古自治區赤峰第四中學2024-2025學年高一下學期4月月考歷史試題(含答案)
- 2025-2030中國保健品行業市場深度調研及競爭格局與投資研究報告
- 2025年江蘇省無錫市錫山區中考英語一模試卷
- (二模)衢州、麗水、湖州2025年4月三地市高三教學質量檢測 語文試卷(含答案解析)
- 宜昌市社區工作者招聘真題2024
- 水下潛水艇課件
- 36 階段統計項目風險管理表甘特圖
- 2025-2030中國電信增值行業運行狀況與發展前景預測研究報告
評論
0/150
提交評論