客户信息可以存在数据库里面,增加的时候,通过代码连接上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("-----------------")
package Test2
import java.util.Scanner
import java.util.Vector
public class A {
static Vector<String>vector=new Vector<>()
public static boolean exist(String value){
if (vector.contains(value)){
return true
}else{
return false
}
}
public Vector<String>categ(){
return vector
}
public static void add(String value){
if (exist(value)){
vector.add(value)
System.out.println("添加成功")
}else{
System.out.println("此书存在,不进行添加")
}
}
public static void modify(String OriginalValue,String ModifyValue){
if (exist(OriginalValue)){
if(exit(ModifyValue)){
int i=vector.indexOf(OriginalValue)
remove(OriginalValue)
vector.add(i, OriginalValue)
System.out.println("修改成功")
}else{
System.out.println("修改后的书存在,不能修改")
}
}else{
System.out.println("此书不存在,请先进行添加 *** 作")
Scanner scanner=new Scanner(System.in)
System.out.println("是否添加此书:(输入\"yes\"进行添加,输入其它任意内容均不添加)")
String s=scanner.nextLine()
if (s.equals("yes")){
add(OriginalValue)
}
scanner.close()
}
}
public static void remove(String value){
if (exist(value)){
vector.remove(value)
System.out.println("删除成功")
}else{
System.out.println("此书不存在")
}
}
}
你需要的是基于gui界面的还是javaweb的呢?这两种项目有共性也有区别, 比如在数据层的部分可以统一的抽象出来公用。
但是在view层差别还蛮大的, swing是各种基于listener来触发业务逻辑, 与javaweb开发不太一样, 我最近两种都有实现, 感受是还算简单。
希望能够帮助你
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)