master
金安民 6 months ago
parent b66f340354
commit dda1cc7ad0

Binary file not shown.

@ -7,69 +7,113 @@ public class DML {
// 使用相对路径
private static final String URL = "jdbc:sqlite:db/dbuml.db3";
@Test
public void create() {
public void createInboundTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建数据表的 SQL 语句
String sql = "create table if not exists xslist (" +
"id integer primary key AUTOINCREMENT not null ," +
"sno text not null," +
"sname text," +
"lx1 integer," +
"lx2 integer" +
// 创建入库记录表
String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" +
"id TEXT PRIMARY KEY NOT NULL," +
"goods_id TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"supplier TEXT," +
"inbound_time TIMESTAMP," +
"operator TEXT," +
"remark TEXT" +
");";
// 执行 SQL 语句
stmt.execute(sql);
System.out.println("数据表 创建成功");
System.out.println("入库记录表创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void deleteAll() {
public void createWarehouseTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 删除所有记录的 SQL 语句
String sql = "DELETE FROM xslist";
// 创建仓库存放数据表
String sql = "CREATE TABLE IF NOT EXISTS warehouse (" +
"id TEXT PRIMARY KEY NOT NULL," +
"goods_id TEXT NOT NULL," +
"goods_name TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"operation_type TEXT NOT NULL," +
"operator TEXT," +
"operation_time TIMESTAMP," +
"supplier TEXT," +
"customer TEXT," +
"remark TEXT" +
");";
// 执行 SQL 语句
int result = stmt.executeUpdate(sql);
System.out.println("删除了 " + result + " 条记录");
stmt.execute(sql);
System.out.println("仓库数据表创建成功");
} catch (SQLException e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void createInboundTable() {
public void createLogTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 创建入库记录表
String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" +
"id TEXT PRIMARY KEY NOT NULL," +
"goods_id TEXT NOT NULL," +
"quantity INTEGER NOT NULL," +
"supplier TEXT," +
"inbound_time TIMESTAMP," +
"operator TEXT," +
"remark TEXT" +
// 创建操作日志数据表
String sql = "CREATE TABLE IF NOT EXISTS operation_logs (" +
"日志id TEXT PRIMARY KEY NOT NULL," + //日志id
"operation_type TEXT NOT NULL," + // 操作类型(入库、出库、修改等)
"operation_target TEXT NOT NULL," + // 操作对象货物ID或名称
"operator TEXT," + // 操作人
"operation_time TIMESTAMP," + // 操作时间
"details TEXT" + // 操作详情
");";
stmt.execute(sql);
System.out.println("入库记录表创建成功");
System.out.println("日志数据表创建成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void clearTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
String sql = "DELETE FROM 表名";
int result = stmt.executeUpdate(sql);
System.out.println("已清空数据表,删除了 " + result + " 条记录");
} catch (SQLException e) {
e.printStackTrace();
}
} //清空指定数据表数据
@Test
public void dropTable() {
try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) {
// 删除表的SQL 语句
String sql = "DROP TABLE IF EXISTS 表名";
// 执行 SQL 语句
stmt.execute(sql);
System.out.println(" 表删除成功");
} catch (SQLException e) {
e.printStackTrace();
}
} //删除指定数据表
}
Loading…
Cancel
Save