客户信息可以存在数据库里面,增加的时候,通过代码连接上mysql数据库,然后拼接sql语句,查询或者增加修改数据库的字段和数据。连接数据库示例:
// 驱动程序名String driver = "com.mysql.jdbc.Driver"
// URL指向要访问的数据库名scutcs
String url = "jdbc:mysql://127.0.0.1:3306/scutcs"
// MySQL配置时的用户名
String user = "root"
// MySQL配置时的密码
String password = "root"
try {
// 加载驱动程序
Class.forName(driver)
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password)
if(!conn.isClosed())
System.out.println("Succeeded connecting to the Database!")
// statement用来执行SQL语句
Statement statement = conn.createStatement()
// 要执行的SQL语句
String sql = "select * from student"
// 结果集
ResultSet rs = statement.executeQuery(sql)
System.out.println("-----------------")
System.out.println("执行结果如下所示:")
System.out.println("-----------------")
System.out.println(" 学号" + "\t" + " 姓名")
System.out.println("-----------------")
1:在网页中编写一个按钮,比如添加用户
<form action="xxx.jsp"/>
<input type="submit" value="添加用户"/>
</form>
2:添加mysql的jdbc驱动jar包
3:编写一个数据库 *** 作辅助类,使用的sql语句,差不多如下
insert into tb_user values(?,?,?)等,你写的太简单,详细点的要求可以发邮件到lixihara@126.com,我会帮你完成哦
import java.util.ArrayListimport java.util.Scanner
/**
*
* @author young
*
*/
class People {
private String name
private String password
private double height
private double tz
private String blood
public People(String name, String password, double height, double tz,
String blood) {
super()
this.name = name
this.password = password
this.height = height
this.tz = tz
this.blood = blood
}
public static ArrayList<People> addPeople(){
ArrayList<People> al = new ArrayList<People>()
Scanner sc = new Scanner(System.in)
System.out.print("请输入姓名:")
String n = sc.next()
System.out.print("请输入密码:")
String pa = sc.next()
System.out.print("请输入身高:")
double h = sc.nextDouble()
System.out.print("请输入体重:")
double t = sc.nextDouble()
System.out.print("请输入血型:")
String b = sc.next()
People p = new People(n, pa, h, t, b)
al.add(p)
System.out.println("添加用户成功!")
return al
}
public static int cd(){
int i
System.out.println("*********************")
System.out.println("*******菜 单********")
System.out.println("***** 1 添加*******")
System.out.println("***** 2 查找*******")
System.out.println("***** 0 退出*******")
System.out.println("*********************")
Scanner sc = new Scanner(System.in)
System.out.print("请输入你的选择:")
i = sc.nextInt()
return i
}
public static void find(ArrayList<People> al){
Scanner sc = new Scanner(System.in)
System.out.print("请输入查找姓名:")
String n = sc.next()
System.out.print("请输入查找密码:")
String pa = sc.next()
for(People p : al){
if(p.name.equals(n) && (p.password.equals(pa))){
System.out.println("姓名:" + p.name + " 身高:" + p.height + " 体重:" + p.tz + " 血型:" + p.blood)
}else {
System.out.println("对不起!查无此人.")
}
}
}
public static void main(String[] args) {
int i
ArrayList<People> al = new ArrayList<People>()
i = cd()
while(i != 0){
switch (i) {
case 1:
al = addPeople()
break
case 2:
find(al)
break
case 0:
System.out.println("退出系统!")
break
default:
break
}
i = cd()
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)