客户信息可以存在数据库里面,增加的时候,通过代码连接上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("-----------------")
public class Customer {
private String customerName
private int age
private boolean isValid
public Customer(String customerName, int age, boolean isValid) {
super()
this.customerName = customerName
this.age = age
this.isValid = isValid
}
public String getCustomerName() {
return customerName
}
public void setCustomerName(String customerName) {
this.customerName = customerName
}
public int getAge() {
return age
}
public void setAge(int age) {
this.age = age
}
public boolean isValid() {
return isValid
}
public void setValid(boolean isValid) {
this.isValid = isValid
}
}
import java.util.ArrayList
import java.util.List
public class CustomerBiz {
private List<Customer> customerList = new ArrayList<Customer>()
public void addCustomer(Customer customer){
customerList.add(customer)
}
public void showCustomers(){
Customer customer = null
System.out.println("客户信息:")
for(int i=0i<customerList.size()i++){
customer = customerList.get(i)
System.out.println(customer.getCustomerName()+" "+customer.getAge()+" "+customer.isValid())
}
}
public static void main(String[] args){
CustomerBiz customerBiz = new CustomerBiz()
customerBiz.addCustomer(new Customer("王一",30,false))
customerBiz.addCustomer(new Customer("郝强",19,true))
customerBiz.showCustomers()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)