package exercise17;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;
/**
* @ClassName: Ex04
* @Description 将第6章的宠物商店程序修改为使用数据库保存全部的宠物信息,并可以实现关键字查找。
* @author 叶青
* @date 2019年05月07日 晚上23:05
*
*/
interface Pet { // 定义一个接口作为可以放入宠物商店到标准,只要是符合该标准的宠物都可以放入商店
public String getName();
public String getColor();
public int getAge();
public void setName(String name);
public void setColor(String color);
public void setAge(int age);
}
class Dog2 implements Pet { // 定义宠物狗的类,并实现Pet接口
private String name;
private String color;
private int age;
public Dog2(String name, String color, int age) {
this.name = name;
this.color = color;
this.age = age;
}
public String getName() {
return this.name;
}
public String getColor() {
return this.color;
}
public int getAge() {
return this.age;
}
public void setName(String name) {
this.name = name;
}
public void setColor(String color) {
this.color = color;
}
public void setAge(int age) {
this.age = age;
}
}
class Cat implements Pet { // 定义宠物猫的类,并实现Pet接口
private String name;
private String color;
private int age;
public Cat(String name, String color, int age) {
this.name = name;
this.color = color;
this.age = age;
}
public String getName() {
return this.name;
}
public String getColor() {
return this.color;
}
public int getAge() {
return this.age;
}
public void setName(String name) {
this.name = name;
}
public void setColor(String color) {
this.color = color;
}
public void setAge(int age) {
this.age = age;
}
}
/**
* 创建一个专门用于操作数据库的类,实现宠物信息的插入、关键字查询、删除操作。
*/
class DbOperater {
private static f
第17章,第六题:将第6章的宠物商店程序修改为使用数据库保存全部的宠物信息,并可以实现关键字查找。
最新推荐文章于 2023-12-03 11:26:21 发布