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"; private static final String URL = "jdbc:sqlite:db/dbuml.db3";
@Test @Test
public void create() { public void createInboundTable() {
try (Connection conn = DriverManager.getConnection(URL); try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) { Statement stmt = conn.createStatement()) {
// 创建数据表的 SQL 语句 // 创建入库记录表
String sql = "create table if not exists xslist (" + String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" +
"id integer primary key AUTOINCREMENT not null ," + "id TEXT PRIMARY KEY NOT NULL," +
"sno text not null," + "goods_id TEXT NOT NULL," +
"sname text," + "quantity INTEGER NOT NULL," +
"lx1 integer," + "supplier TEXT," +
"lx2 integer" + "inbound_time TIMESTAMP," +
"operator TEXT," +
"remark TEXT" +
");"; ");";
// 执行 SQL 语句
stmt.execute(sql); stmt.execute(sql);
System.out.println("入库记录表创建成功");
System.out.println("数据表 创建成功");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void deleteAll() { public void createWarehouseTable() {
try (Connection conn = DriverManager.getConnection(URL); try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) { 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 语句 stmt.execute(sql);
int result = stmt.executeUpdate(sql); System.out.println("仓库数据表创建成功");
System.out.println("删除了 " + result + " 条记录");
} catch (SQLException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void createInboundTable() { public void createLogTable() {
try (Connection conn = DriverManager.getConnection(URL); try (Connection conn = DriverManager.getConnection(URL);
Statement stmt = conn.createStatement()) { Statement stmt = conn.createStatement()) {
// 创建入库记录表 // 创建操作日志数据表
String sql = "CREATE TABLE IF NOT EXISTS inbound_records (" + String sql = "CREATE TABLE IF NOT EXISTS operation_logs (" +
"id TEXT PRIMARY KEY NOT NULL," + "日志id TEXT PRIMARY KEY NOT NULL," + //日志id
"goods_id TEXT NOT NULL," + "operation_type TEXT NOT NULL," + // 操作类型(入库、出库、修改等)
"quantity INTEGER NOT NULL," + "operation_target TEXT NOT NULL," + // 操作对象货物ID或名称
"supplier TEXT," + "operator TEXT," + // 操作人
"inbound_time TIMESTAMP," + "operation_time TIMESTAMP," + // 操作时间
"operator TEXT," + "details TEXT" + // 操作详情
"remark TEXT" +
");"; ");";
stmt.execute(sql); stmt.execute(sql);
System.out.println("入库记录表创建成功"); System.out.println("日志数据表创建成功");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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