用jdbc實作寵物商店管理系統
1,開發語言:java(JDK8)
2,開發工具:IntelliJ IDEA 2021.2.3
3,資料庫:MySQL
4,作業系統:Windows10
5,需要引入的jar包:mysql-connector-java-8.0.26.jar,下載地址:https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.26
因為上篇的資料庫檔案沒有了,重新建了資料庫以及修改了代碼里的腳本,用下面的新代碼就可以了
以下是運行圖片:




代碼實作:
邏輯代碼
package com.impl;
import com.dao.BaseDAO;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* @author 咕嚕科
* ClassName: PetManage
* date: 2021/8/26 22:12
* Description:
* version 1.0
*/
public class PetManage extends BaseDAO {
/**
*
*/
public void showAll() {
showPetName();
showPetOwner();
showPetStore();
login();
}
/**
* 顯示寵物的姓名以及ID方法
*/
public void showPetName() {
conn = getConnection();
String sql = "SELECT id,pet_name from pet";
try {
state = conn.prepareStatement(sql);
rs = state.executeQuery();
System.out.println("Wonderland醒來,所有寵物從MySQL中醒來");
System.out.println("*************************************");
int num = 1;
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("pet_name");
System.out.println("第" + num + "只寵物,名字叫:" + name);
num++;
}
System.out.println("*************************************\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
closeObject1();
}
}
/**
* 顯示寵物主人方法
*/
public void showPetOwner() {
conn = getConnection();
String sql = "select id,owner_id,owner_name,money from pet_owner where owner_type = 1";
try {
state = conn.prepareStatement(sql);
rs = state.executeQuery();
System.out.println("所有寵物主人從MySQL中醒來");
System.out.println("*************************************");
int num = 1;
while (rs.next()) {
String name = rs.getString("owner_name");
System.out.println("第" + num + "主人的名字叫:" + name);
num++;
}
System.out.println("*************************************\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
closeObject1();
}
}
/**
* 顯示寵物商店方法
*/
public void showPetStore() {
conn = getConnection();
String sql = "select id,owner_id,owner_name,money,address from pet_owner where owner_type = 2";
try {
state = conn.prepareStatement(sql);
rs = state.executeQuery();
System.out.println("所有寵物商店從MySQL中醒來");
System.out.println("*************************************");
int num = 1;
while (rs.next()) {
String storeName = rs.getString("owner_name");
String storeAddress = rs.getString("address");
System.out.println("第" + num + "個商店的名字叫: " + storeName + " ,地址在: " + storeAddress);
num++;
}
System.out.println("*************************************\n");
} catch (Exception e) {
e.printStackTrace();
} finally {
closeObject1();
}
}
/**
* 登錄界面選擇是主人登錄還是商店登錄方法
*/
public void login() {
System.out.println("請選擇輸入登錄模式\n1.寵物主人登錄\n2.寵物商店登錄\n3.退出系統\n-------------------");
try {
Scanner input = new Scanner(System.in);
int choise = input.nextInt();
if (choise < 1 || choise > 3) {
System.out.println("輸入有誤,請重新選擇");
login();
} else {
switch (choise) {
case 1:
petOwnerLogin();
break;
case 2:
petStoreLogin();
break;
case 3:
System.out.println("謝謝使用");
System.exit(0);
break;
default:
break;
}
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤,請重新選擇");
login();
}
}
/**
* 寵物主人登錄方法
*
* @return
*/
public boolean petOwnerLogin() {
boolean flag = false;
try {
Scanner input = new Scanner(System.in);
System.out.println("請先登錄,請您先輸入主人的名字");
String name = input.next();
System.out.println("請您輸入主人的密碼:");
String password = input.next();
conn = getConnection();
String sql = "SELECT owner_name,password from pet_owner where owner_name=? and password=?";
try {
state = conn.prepareStatement(sql);
state.setString(1, name);
state.setString(2, password);
rs = state.executeQuery();
if (rs.next()) {
System.out.println("---------恭喜您成功登錄!---------");
System.out.println("----------您的基本資訊---------");
conn = getConnection();
String sql2 = "SELECT id,owner_name,owner_id,password,money from pet_owner where owner_name=?";
// state=conn.prepareStatement(sql2);
// state.setString(1, name);
// rs=state.executeQuery();
rs = search(sql2, name);
if (rs.next()) {
int uid = rs.getInt("owner_id");
String uname = rs.getString("owner_name");
Double uMoney = rs.getDouble("money");
System.out.println("登錄成功!!!!");
System.out.println("姓名:" + uname);
System.out.println("元寶數:" + uMoney);
dealPet(uname, uid);
}
} else {
System.out.println("登錄失敗,賬戶與密碼不匹配");
login();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤");
login();
}
return false;
}
/**
* 選擇買寵物或者賣寵物的方法
*/
public void dealPet(String ownerName, int uid) {
System.out.println("您可以購買和賣出寵物,購買寵物請輸入1,賣出寵物請輸入2\n1.購買寵物\n2.賣出寵物\n3.回傳上一級\n4.退出系統");
try {
Scanner input2 = new Scanner(System.in);
int choise2 = input2.nextInt();
if (choise2 < 1 || choise2 > 4) {
System.out.println("輸入有誤");
dealPet(ownerName, uid);
} else {
switch (choise2) {
case 1:
//購買寵物
buyPet(ownerName, uid);
break;
case 2:
//出售寵物
showSellPet(ownerName, uid);
break;
case 3:
//回傳上一級
login();
break;
case 4:
System.out.println("--------謝謝使用------");
System.exit(0);
default:
break;
}
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤");
dealPet(ownerName, uid);
}
}
/**
* 顯示主人擁有的寵物
*/
public void showSellPet(String ownerName, int uid) {
conn = getConnection();
String sql25 = "select id,pet_name,pet_price,pet_role_type,pet_type from pet where owner_type = 1 and owner_id =" + uid;
try {
state = conn.prepareStatement(sql25);
rs = state.executeQuery();
System.out.println("以下是你擁有的寵物:");
// //如果結果集為空,即該主人沒有寵物,就回傳上一級進行選擇
// if(!rs.next()){
// System.out.println("您沒有寵物,將自動回傳上一級");
// buyPet(ownerName, uid);
// }
int num = 1;
while (rs.next()) {
int petid = rs.getInt("id");
String petName = rs.getString("pet_name");
String petPrice = rs.getString("pet_price");
System.out.println("這是" + num + "只寵物,編號是" + petid + ",名字叫:" + petName + ",需要" + petPrice + "個元寶");
num++;
}
System.out.println("**************************************");
} catch (SQLException e) {
e.printStackTrace();
}
closeObject1();
sellPet(ownerName, uid);
}
public void sellPet(String ownerName, int uid) {
System.out.println("請輸入你想賣出的寵物編號:");
try {
Scanner input27 = new Scanner(System.in);
int choisePetId = input27.nextInt();
//先查詢下有哪些商店
String queryStore = "select owner_id,owner_name from pet_owner where owner_type = 2";
Connection queryStoreConn = getConnection();
try {
state = queryStoreConn.prepareStatement(queryStore);
rs = state.executeQuery();
int num = 1;
if (rs.next()) {
//說明有商店存在
System.out.println("請輸入你要賣給的商店編號");
int storeId1 = rs.getInt("owner_id");
String storeName = rs.getString("owner_name");
System.out.println(num + "." + storeName+"編號\t:"+storeId1);
num++;
while (rs.next()) {
int storeId = rs.getInt("owner_id");
String storeName2 = rs.getString("owner_name");
System.out.println(num + "." + storeName2+"\t編號:"+storeId);
num++;
}
System.out.println("8888.回傳上一級\n9999.退出系統");
int storeId = input27.nextInt();
if (storeId == 8888) {
dealPet(ownerName, uid);
} else if (storeId == 9999) {
System.out.println("-------謝謝使用-------");
System.exit(0);
}
String sql30 = "select pet_name,pet_price,pet_role_type,pet_type from pet where owner_type = 1 and owner_id = "+uid+" and id = "+choisePetId;
Connection conn6 = getConnection();
try {
state = conn6.prepareStatement(sql30);
rs = state.executeQuery();
if (rs.next()) {
String petPrice = rs.getString("pet_price");//寵物價格
Connection conn9 = getConnection();
conn9.setAutoCommit(false);
//修改寵物資訊
String sql40 = "update pet set owner_type= 2,owner_id=" + storeId + " where id=" + choisePetId;
state = conn9.prepareStatement(sql40);
int result20 = state.executeUpdate();
//賣主加錢
String sql41 = "update pet_owner set money = money +" + petPrice + " where owner_type = 1 and owner_id =" +uid;
state = conn9.prepareStatement(sql41);
int result21 = state.executeUpdate();
//商店扣錢
String sql42 = "update pet_owner set money = money -" + petPrice + " where owner_type = 2 and owner_id =" + storeId;
state = conn9.prepareStatement(sql42);
int result22 = state.executeUpdate();
//獲得當前時間
Long time1 = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dealTime = sdf.format(time1);
//將該條交易添加至交易賬單中
String sql43 = "insert into account_info (account_type,pet_id,sale_owner_id,buy_owner_id,price,create_time) VALUES (2," + choisePetId + "," + storeId + "," + uid + "," + petPrice + ",'" + dealTime + "')";
state = conn9.prepareStatement(sql43);
int result23 = state.executeUpdate();
if (result20 > 0 && result21 > 0 && result22 > 0 & result23 > 0) {
//提交事務
conn9.commit();
System.out.println("賣出成功");
} else {
//回滾事務
System.out.println("出售失敗");
conn9.rollback();
}
dealPet(ownerName, uid);
} else {
System.out.println("沒有該寵物,賣出失敗");
dealPet(ownerName, uid);
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("系統例外");
dealPet(ownerName, uid);
}
} else {
//沒有商店,回傳到上一級
dealPet(ownerName, uid);
}
} catch (SQLException e) {
e.printStackTrace();
System.out.println("資料庫查詢例外!!!");
dealPet(ownerName, uid);
}
} catch (InputMismatchException e) {
System.out.println("輸入錯誤,請重新輸入");
sellPet(ownerName, uid);
}
}
// /**
// * 顯示新培育寵物并且購買
// */
// public void showNewPet() {
// // TODO Auto-generated method stub
//
// }
/**
* 寵物商店登錄的方法
*
* @return
*/
public boolean petStoreLogin() {
boolean flag = false;
try {
Scanner input = new Scanner(System.in);
System.out.println("請先登錄,請您先輸入寵物商店的名字");
String name = input.next();
System.out.println("請您輸入寵物商店的密碼:");
String password = input.next();
conn = getConnection();
String sq110 = "select owner_id,owner_name,money from pet_owner where owner_type = 2 and owner_name=? and password=?";
state = conn.prepareStatement(sq110);
rs = search(sq110, name, password);
if (rs.next()) {
String storeId = rs.getString("owner_id");
System.out.println("登錄成功");
PetStoreMake(name,storeId);
} else {
System.out.println("登錄失敗");
login();
}
} catch (Exception e) {
// TODO: handle exception
}
return false;
}
/*
* 寵物商店培育新寵物
*/
public void PetStoreMake(String storeName,String storeId) throws SQLException {
System.out.println("請輸入數字進行選擇:\n1.查詢店內寵物\n2.培育新寵物\n3.退出登錄\n4.退出系統");
try {
Scanner input = new Scanner(System.in);
int choise7 = input.nextInt();
if (choise7 < 1 || choise7 > 3) {
System.out.println("輸入有誤");
PetStoreMake(storeName,storeId);
} else {
switch (choise7) {
case 1:
storePetQuery(storeName,storeId);
break;
case 2:
storeAddPet(storeName,storeId);
break;
case 3:
//退出登錄,回傳上一級
login();
break;
case 4:
System.out.println("-------謝謝使用-------");
System.exit(0);
default:
break;
}
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤");
PetStoreMake(storeName,storeId);
}
}
/**
* 寵物商店培育新寵物的方法
*
* @param storeName
* @throws SQLException
*/
public void storeAddPet(String storeName,String storeId) throws SQLException {
System.out.println("請輸入你想添加的寵物的品種名稱(例如:金漸層):");
Scanner input = new Scanner(System.in);
String typename = input.next();
System.out.println("請輸入該寵物的名字:");
String petName = input.next();
System.out.println("請輸入該寵物的型別:\n1.普通寵物\n2.新型寵物");
int animalType = input.nextInt();
System.out.println("請輸入該寵物的價格:");
int price = input.nextInt();
try {
Connection conn9 = getConnection();
String sql13 = "insert into pet(pet_name,owner_id,owner_type,pet_price,pet_role_type,pet_type) values ('"+petName+"',"+storeId+",2,"+price+",'"+animalType+"','"+typename+"')";
state = conn9.prepareStatement(sql13);
int a = state.executeUpdate();
if (a > 0) {
System.out.println("培育新寵物成功");
PetStoreMake(storeName,storeId);
} else {
System.out.println("培育新寵物失敗");
PetStoreMake(storeName,storeId);
}
}catch (Exception e){
e.printStackTrace();
}
}
/**
* 在商店登錄之后進行對店內的寵物進行查詢
*
* @param storeName
*/
public void storePetQuery(String storeName,String storeId) {
System.out.println("正在查詢店內寵物,,,");
conn = getConnection();
String sql11 = "select id,pet_name,pet_price,pet_role_type,pet_type from pet where owner_type = 2 and owner_id = " + storeId;
try {
state = conn.prepareStatement(sql11);
rs = state.executeQuery();
int i = 1;
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("pet_name");
String typename = rs.getString("pet_type");
String petPrice = rs.getString("pet_price");
System.out.println("第" + i + "只寵物編號是:"+id+",名字:" + name + ",寵物型別:" + typename + ",價格:" + petPrice);
i++;
}
System.out.println("----------------------------");
PetStoreMake(storeName,storeId);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 購買寵物的方法
*/
public void buyPet(String ownerName, int uid) {
System.out.println("請輸入選擇購買范圍,只輸入選擇項的序號");
System.out.println("1:購買庫存寵物\n2.購買新培育寵物\n3.回傳上一級");
try {
Scanner input3 = new Scanner(System.in);
int choise5 = input3.nextInt();
if (choise5 < 1 || choise5 > 3) {
System.out.println("輸入有誤");
buyPet(ownerName, uid);
} else {
switch (choise5) {
case 1:
showPetAll(ownerName, uid, 2);
break;
case 2:
buyNewPet(ownerName, uid, 2);
break;
case 3:
//回傳上一級
dealPet(ownerName, uid);
break;
default:
break;
}
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤");
buyPet(ownerName, uid);
}
}
public void buyNewPet(String ownerName, int uid, int petRoleType) {
//用于判斷查詢是否有結果
boolean havePet = false;
System.out.println("正在幫你查詢新寵物,,,,,");
conn = getConnection();
String sql31 = "SELECT id,pet_name,pet_price from pet where pet_role_type= 2 and owner_type = 2";
try {
state = conn.prepareStatement(sql31);
rs = state.executeQuery();
while (rs.next()) {
int petid = rs.getInt("id");
String petName = rs.getString("pet_name");
String petPrice = rs.getString("pet_price");
System.out.println("序號為:" + petid + ",名字為:" + petName + ",需要" + petPrice + "個元寶");
havePet = true;
}
if (havePet) {
System.out.println("請輸入你要購買的新寵物的序號:");
try {
// boolean havePet2=false;
Scanner input28 = new Scanner(System.in);
int newPetId = input28.nextInt();
Connection conn7 = getConnection();
String sql32 = "SELECT id,pet_name,pet_price,pet_role_type,owner_id from pet where owner_type = 2 and id = " + newPetId;
state = conn7.prepareStatement(sql32);
rs = state.executeQuery();
if (rs.next()) {
int storeid = rs.getInt("owner_id");
int petPrice = rs.getInt("pet_price");
Connection conn8 = getConnection();
conn8.setAutoCommit(false);
//修改寵物所屬資訊
String sql33 = "update pet set owner_type= 1,owner_id=" + uid + " where id=" + newPetId;
//修改買主賬戶金額
String sql34 = "update pet_owner set money=money-" + petPrice + " where owner_type = 1 and owner_id =" + uid;
//修改商店金額
String sql35 = "update pet_owner set money=money+" + petPrice + " where owner_type = 2 and owner_id =" + storeid;
//獲得當前時間
Long time1 = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dealTime = sdf.format(time1);
//將該條交易添加至交易賬單中
String sql36 = "insert into account_info (account_type,pet_id,sale_owner_id,buy_owner_id,price,create_time) VALUES (2," + newPetId + "," + storeid + "," + uid + "," + petPrice + ",'" + dealTime + "')";
state = conn8.prepareStatement(sql33);
int result13 = state.executeUpdate();
state = conn8.prepareStatement(sql34);
int result14 = state.executeUpdate();
state = conn8.prepareStatement(sql35);
int result15 = state.executeUpdate();
state = conn8.prepareStatement(sql36);
int result16 = state.executeUpdate();
if (result13 > 0 && result14 > 0 && result15 > 0 && result16 > 0) {
//如果都成功執行,改變資料,那就提交事務
conn8.commit();
System.out.println("購買成功");
} else {
//如果中加你有一條沒有執行成功那就回滾事務
System.out.println("購買失敗");
conn8.rollback();
}
buyPet(ownerName, uid);
} else {
System.out.println("輸入錯誤,沒有該序號的新寵物");
buyNewPet(ownerName, uid, 2);
}
} catch (InputMismatchException e) {
e.printStackTrace();
}
} else {
System.out.println("暫時還沒新寵物");
buyPet(ownerName, uid);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 展示庫存寵物名字,序號,型別的方法
*/
public void showPetAll(String ownerName, int uid, int petRoleType) {
System.out.println("---------以下是庫存寵物--------");
conn = getConnection();
String sql6 = "SELECT pet.id,pet_name,pet_type,pet_role_type,pet_price,pet.owner_id,pet.owner_type,owner_name from pet,pet_owner where pet.owner_id = pet_owner.owner_id and pet_role_type = 1 and pet.owner_type = 2";
try {
state = conn.prepareStatement(sql6);
rs = state.executeQuery();
while (rs.next()) {
int petId = rs.getInt("pet.id");
int owner_id = rs.getInt("pet.owner_id");
String petName = rs.getString("pet_name");
String storeName = rs.getString("owner_name");
String petType = rs.getString("pet_type");
String money = rs.getString("pet_price");
System.out.println("序號:" + petId + ",我的名字叫:" + petName + ",我的品種是:" + petType + ",要購買我要花:" + money + "個元寶!我屬于:" + storeName);
}
System.out.println("請輸入你想購買的寵物編號:");
try {
Scanner input17 = new Scanner(System.in);
int choise6 = input17.nextInt();
//對在商店里的寵物進行ID查詢,符合的就購買
conn = getConnection();
String sql15 = "select id,pet_name,pet_price,pet_role_type,pet_type,owner_id from pet where id =" + choise6;
try {
state = conn.prepareStatement(sql15);
rs = state.executeQuery();
if (rs.next()) {
//這里是寵物主人購買寵物的代碼,將寵物的store_ID設定為null,將寵物的owner_ID設定為購買主人的ID
//然后主人賬戶減錢,商店的結余加錢,將該條交易添加至交易賬單中
int store_id = rs.getInt("owner_id");//這里是選擇的寵物所屬商店的ID
int petPrice = rs.getInt("pet_price");//寵物價格
//這里用創建一個新的連接
Connection conn1 = getConnection();
//開啟事務
conn1.setAutoCommit(false);
//將寵物的主人型別改為個人- 1,將寵物的主人id設定為購買主人的ID
String sql18 = "update pet set owner_type=1,owner_id=" + uid + " where pet.id=" + choise6;
//寵物主人減錢
String sql19 = "update pet_owner set money = money -" + petPrice + " where owner_type = 1 and owner_id=" + uid;
//寵物商店加錢
String sql20 = "update pet_owner set money = money +" + petPrice + " where owner_type = 2 and owner_id=" + store_id;
//獲得當前時間
Long time1 = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dealTime = sdf.format(time1);
//將該條交易添加至交易賬單中
String sql21 = "insert into account_info (account_type,pet_id,sale_owner_id,buy_owner_id,price,create_time) VALUES (1," + choise6 + "," + store_id + "," + uid + "," + petPrice + ",'" + dealTime + "')";
state = conn1.prepareStatement(sql18);
int result2 = state.executeUpdate();
state = conn1.prepareStatement(sql19);
int result3 = state.executeUpdate();
state = conn1.prepareStatement(sql20);
int result4 = state.executeUpdate();
state = conn1.prepareStatement(sql21);
int result5 = state.executeUpdate();
if (result2 > 0 && result3 > 0 && result4 > 0 && result5 > 0) {
//如果都成功執行,改變資料,那就提交事務
conn1.commit();
System.out.println("購買成功");
} else {
//如果中加你有一條沒有執行成功那就回滾事務
System.out.println("購買失敗");
conn1.rollback();
}
//回傳上一級
buyPet(ownerName, uid);
} else {
System.out.println("購買失敗");
//回傳上一級
buyPet(ownerName, uid);
}
} catch (SQLException e) {
e.printStackTrace();
}
} catch (InputMismatchException e) {
System.out.println("輸入有誤");
showPetAll(ownerName, uid, 1);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
操作資料庫的工具類BaseDAO:
package com.dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author 咕嚕科
* ClassName: BaseDao
* date: 2021/8/26 22:11
* Description:
* version 1.0
*/
public class BaseDAO {
public Connection conn = null;
public PreparedStatement state = null;
public ResultSet rs = null;
/**
* 獲取連接物件
* @return
*/
public Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pet_store", "root", "123");
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public int update(String sql, Object...obs) throws SQLException {
int result = 0;
conn = getConnection();
state = conn.prepareStatement(sql);
for (int i = 0; i < obs.length; i++) {
state.setObject(i + 1, obs[i]);
}
result = state.executeUpdate();
return result;
}
public ResultSet search(String sql, Object...obs) {
try {
conn = getConnection();
state = conn.prepareStatement(sql);
for (int i = 0; i < obs.length; i++) {
state.setObject(i + 1, obs[i]);
}
rs = state.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public void closeObject1() {
try {
if (rs != null) {
rs.close();
}
if (state != null) {
state.close();
}
if (conn != null) {
conn.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void closeObject2(AutoCloseable... obs) {
try {
for (int i = 0; i < obs.length; i++) {
if (obs[i] != null) {
obs[i].close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Main方法入口:
public class MainTest {
public static void main(String[] args) {
System.out.println("=========寵物商店啟動=======");
PetManage pm = new PetManage();
//顯示所有寵物
pm.showAll();
}
}
需要將jar包匯入,才能正常運行

資料庫表
寵物表(pet)
/*
Navicat MySQL Data Transfer
Source Server : hth
Source Server Version : 50562
Source Host : localhost:3306
Source Database : pet_store
Target Server Type : MYSQL
Target Server Version : 50562
File Encoding : 65001
Date: 2021-11-07 20:28:33
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `pet`
-- ----------------------------
DROP TABLE IF EXISTS `pet`;
CREATE TABLE `pet` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`pet_name` varchar(20) NOT NULL,
`pet_price` decimal(10,2) NOT NULL,
`pet_role_type` int(3) NOT NULL DEFAULT '1' COMMENT '寵物型別:1-普通寵物;2-培育寵物',
`pet_type` varchar(20) NOT NULL COMMENT '寵物品種',
`owner_id` int(5) NOT NULL,
`owner_type` int(5) NOT NULL COMMENT '主人型別:1-個人;2-商店',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of pet
-- ----------------------------
INSERT INTO `pet` VALUES ('1', '歡歡', '5.00', '1', '哈士奇', '1', '1');
INSERT INTO `pet` VALUES ('2', '齊齊', '10.00', '1', '藏獒', '4', '2');
INSERT INTO `pet` VALUES ('3', '露露', '20.00', '1', '銀漸層', '3', '1');
INSERT INTO `pet` VALUES ('4', '布布1', '5.00', '1', '金毛', '3', '1');
INSERT INTO `pet` VALUES ('5', '布布2', '5.00', '1', '哈士奇', '4', '2');
INSERT INTO `pet` VALUES ('6', '布布3', '5.00', '1', '銀漸層', '5', '2');
INSERT INTO `pet` VALUES ('7', '布布4', '5.00', '1', '金毛', '4', '2');
INSERT INTO `pet` VALUES ('8', '布布5', '5.00', '1', '銀漸層', '5', '2');
INSERT INTO `pet` VALUES ('9', '布布6', '5.00', '1', '哈士奇', '4', '2');
INSERT INTO `pet` VALUES ('10', '布布7', '5.00', '1', '金毛', '5', '2');
INSERT INTO `pet` VALUES ('11', '龍龍1', '30.00', '2', '哈士奇', '3', '1');
INSERT INTO `pet` VALUES ('12', '龍龍2', '40.00', '2', '銀漸層', '5', '2');
INSERT INTO `pet` VALUES ('13', '龍龍3', '50.00', '2', '藏獒', '4', '2');
INSERT INTO `pet` VALUES ('14', '小輝2', '50.00', '2', '金漸層', '4', '2');
INSERT INTO `pet` VALUES ('15', '小輝3', '50.00', '2', '金漸層', '4', '2');
INSERT INTO `pet` VALUES ('16', '小輝4', '50.00', '2', '金漸層', '4', '2');
INSERT INTO `pet` VALUES ('17', '小哈', '50.00', '2', '金漸層', '5', '2');
INSERT INTO `pet` VALUES ('18', '小哈', '5.00', '1', '金漸層', '5', '2');
用戶-商店資訊表(pet_owner)
/*
Navicat MySQL Data Transfer
Source Server : hth
Source Server Version : 50562
Source Host : localhost:3306
Source Database : pet_store
Target Server Type : MYSQL
Target Server Version : 50562
File Encoding : 65001
Date: 2021-11-07 20:28:44
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `pet_owner`
-- ----------------------------
DROP TABLE IF EXISTS `pet_owner`;
CREATE TABLE `pet_owner` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner_id` int(11) NOT NULL,
`owner_name` varchar(20) NOT NULL COMMENT '寵物擁有者名稱',
`owner_type` int(11) NOT NULL DEFAULT '1' COMMENT '主人型別:1-個人;2-商店',
`money` decimal(11,0) NOT NULL DEFAULT '0' COMMENT '金幣',
`address` varchar(30) DEFAULT NULL,
`password` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of pet_owner
-- ----------------------------
INSERT INTO `pet_owner` VALUES ('10', '3', 'hth', '1', '9825', '江西', '123');
INSERT INTO `pet_owner` VALUES ('12', '2', '韋德', '1', '14710', '湖北', '123');
INSERT INTO `pet_owner` VALUES ('13', '1', 'kobe', '1', '5000', '山東', '123');
INSERT INTO `pet_owner` VALUES ('14', '4', '重慶觀音橋', '2', '332240', '重慶', '123');
INSERT INTO `pet_owner` VALUES ('15', '5', '西苑', '2', '134625', '深圳', '123');
交易資訊表(account_info)
/*
Navicat MySQL Data Transfer
Source Server : hth
Source Server Version : 50562
Source Host : localhost:3306
Source Database : pet_store
Target Server Type : MYSQL
Target Server Version : 50562
File Encoding : 65001
Date: 2021-11-07 20:28:39
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for `account_info`
-- ----------------------------
DROP TABLE IF EXISTS `account_info`;
CREATE TABLE `account_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account_type` varchar(255) DEFAULT NULL,
`buy_owner_id` int(11) NOT NULL,
`buy_owner_name` varchar(30) DEFAULT NULL,
`buy_owner_type` int(11) DEFAULT NULL,
`sale_owner_id` int(11) NOT NULL,
`sale_owner_type` int(11) DEFAULT NULL,
`sale_owner_name` varchar(30) DEFAULT NULL,
`pet_id` int(11) NOT NULL,
`price` decimal(10,0) DEFAULT NULL,
`create_time` varchar(30) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of account_info
-- ----------------------------
INSERT INTO `account_info` VALUES ('8', '1', '3', null, null, '4', null, null, '2', '5', '2021-11-07 17:51:38');
INSERT INTO `account_info` VALUES ('9', '1', '3', null, null, '5', null, null, '4', '5', '2021-11-07 17:52:23');
INSERT INTO `account_info` VALUES ('10', '2', '3', null, null, '5', null, null, '3', '20', '2021-11-07');
INSERT INTO `account_info` VALUES ('11', '2', '3', null, null, '4', null, null, '11', '30', '2021-11-07');
INSERT INTO `account_info` VALUES ('12', '2', '3', null, null, '5', null, null, '12', '40', '2021-11-07');
INSERT INTO `account_info` VALUES ('13', '2', '3', null, null, '4', null, null, '13', '50', '2021-11-07');
INSERT INTO `account_info` VALUES ('16', '2', '3', null, null, '4', null, null, '2', '10', '2021-11-07');
INSERT INTO `account_info` VALUES ('17', '1', '3', null, null, '4', null, null, '2', '10', '2021-11-07 20:14:25');
INSERT INTO `account_info` VALUES ('18', '2', '3', null, null, '4', null, null, '11', '30', '2021-11-07');
INSERT INTO `account_info` VALUES ('19', '2', '3', null, null, '4', null, null, '2', '10', '2021-11-07');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/352190.html
標籤:其他
上一篇:windows螢屏錄制實作方法
