一个简单的JAVA和ACCESS数据库写的库户信息管理系统
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
//一个简单的JAVA和ACCESS写的用户信息管理程序。
import java.sql.*;
import java.util.Scanner;
import java.util.Random;
public class Customer {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
Connection con;
Statement sql;
ResultSet rs = null;
String username, chioce = "y";
int option = 0,i;
try {
Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
} catch (ClassNotFoundException e) {
System.out.println("");
}
while ("y".equals(chioce)) {
System.out.println("*******欢迎使用大富翁客户抽奖系统*******");
System.out.println("****************************************");
System.out.println("************ 1 客户注册**************");
System.out.println("************ 2 客户信息**************");
System.out.println("************ 3 客户登录**************");
System.out.println("************ 4 参与抽奖**************");
System.out.println("****************************************");
System.out.println("请输入所选操作序号:");
int number = input.nextInt();
switch (number) {
case 1:
for (;;) {
System.out.println("请输入姓名:");
username = input.next();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "",
"");
sql = con.createStatement();
rs = sql
.executeQuery("SELECT * FROM Customer where user='"
+ username + "'");
if (rs.next())
System.out.println("用户名已被注册,请重新输入!");
else
break;
con.close();
} catch (SQLException e) {
System.out.println(e);
}
}
System.out.println("请输入密码:");
int mima = input.nextInt();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "", "");
sql = con.createStatement();
int indata = sql
.executeUpdate("INSERT INTO Customer(user,password) VALUES('"
+ username + "','" + mima + "')");
con.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("注册成功!");
System.out.println("是否继续y(是)/n(否):");
chioce = input.next();
break;
case 2:
System.out.println("此操作需要管理员权限,请登录管理员帐号:");
System.out.print("帐号:");
String admin = input.next();
System.out.print("密码:");
int adminnub = input.nextInt();
if ("admin".equals(admin) && adminnub == 123456) {
System.out
.println("***************************************");
System.out.println("1 查看指定用户信息");
System.out.println("2 客户所有用户信息");
System.out.println("3 修改用户信息");
System.out.println("4 删除用户信息");
System.out
.println("***************************************");
System.out.println("请输入所选操作序号:");
option = input.nextInt();
}
else
System.out.println("登录失败,非管理员帐号!");
switch (option) {
case 0:
break;
case 1:
System.out.println("请输入所查用户名:");
String name2 = input.next();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "",
"");
sql = con.createStatement();
rs = sql
.executeQuery("SELECT * FROM Customer where user='"
+ name2 + "'");
while (rs.next()) {
String name = rs.getString(2);
String password = rs.getString(3);
System.out.println("用户信息为:" + name + password);
}
con.close();
} catch (SQLException e) {
System.out.println(e);
}
break;
case 2:
try {
con = DriverManager.getConnection("jdbc:odbc:test", "",
"");
sql = con.createStatement();
rs = sql.executeQuery("SELECT *FROM Customer");
while (rs.next()) {
String name = rs.getString(2);
String password = rs.getString(3);
System.out.println("用户信息为:" + name + password);
}
con.close();
} catch (SQLException e) {
System.out.println(e);
}
break;
case 3:
System.out.println("请输入所需修改用户名:");
String name3 = input.next();
System.out.println("请输入新用户名:");
String name4 = input.next();
System.out.println("请输入新密码:");
int mima4 = input.nextInt();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "",
"");
sql = con.createStatement();
int indata = sql
.executeUpdate("UPDATE Customer SET user='"
+ name4 + "',password=" + mima4
+ " where user='" + name3 + "'");
con.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("修改用户信息成功!");
break;
case 4:
System.out.println("请输入所需删除用户名:");
String name5 = input.next();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "",
"");
sql = con.createStatement();
int indata = sql
.executeUpdate("DELETE FROM Customer WHERE user='"+name5+"'");
con.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("删除用户信息成功!");
break;
}
System.out.println("是否继续y(是)/n(否):");
chioce = input.next();
break;
case 3:
System.out.println("请输入用户名:");
String name = input.next();
System.out.println("请输入密码:");
String password = input.next();
try {
con = DriverManager.getConnection("jdbc:odbc:test", "", "");
sql = con.createStatement();
rs = sql.executeQuery("SELECT * FROM Customer where user='"
+ name + "'and password=" + password + "");
if (rs.next())
System.out.println("登录成功!");
else
System.out.println("用户名或密码错误,请重新输入");
con.close();
} catch (SQLException e) {
System.out.println(e);
}
System.out.println("是否继续y(是)/n(否):");
chioce = input.next();
break;
case 4:
System.out.println("请输入会员号(会员号码为四位数字):");
int rannub=input.nextInt();
while(rannub<1000||rannub>9999)
{
System.out.println("输入有误,请重新输入:");
rannub=input.nextInt();
}
Random random=new Random();
System.out.println("本次的中奖会员号码是:");
for(i=0;i<6;i++){
int znub=random.nextInt(8999)+1000;
System.out.print(znub+"\t");
if(rannub==znub)
System.out.println("恭喜中奖!!");
}
System.out.println("");
if(i==6)System.out.println("非常遗憾,您的会员号码不再中奖会员号码之中。
"); System.out.println("是否继续y(是)/n(否):");
chioce = input.next();
break;
}
}
}
}。