1. 建立两张表
商品类型表
create table commoditytype(
ctid int auto_increment primary key, 整数自增主键
ctname varchar(50) not null unique key 字符串最大长度50,不能为空,不能重复
);
商品信息表
create table commodityinfo(
cmmit int auto_increment primary key, 整数自增主键
ctid int not null references commoditytype(ctid), 外键关联z商品类型表主键ctid,不能为空
cmmname varchar(100) not null, 字符串最大长度100,不能为空
cmmprice decimal(10,2) not null, 小数最大长度10,精度保留2位,不能为空
salecount int not null 整数,不能为空
);
2. 创建JDBC
复杂方法
创建mysql.properties,将四大金刚数据放入其中,供后续调用
mysql.url = "jdbc:mysql://192.168.145.222:3306/test?useSSL=true&useUnicode=true&characterEncoding=utf-8";
mysql.user = "root";
mysql.password = "root";
mysql.driver="com.mysql.jdbc.Driver";
package org.zzz;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.*;
import java.util.*;
public class exercise{
private static Properties prop;
public static void init(String path)throws IOException,ClassNotFoundException{
prop=new Properties();
prop.load(new FileReader(path));
Class.forName(prop.getProp