Skip to content

Commit f419728

Browse files
committed
feat(database): 添加SQLite数据库支持并优化数据库配置
- 在pom.xml中添加SQLite JDBC依赖 - 在Configuration类中添加SQLite数据库URL常量 - 修改DatabaseController以支持SQLite数据库连接和初始化 - 更新Main类添加数据库模式配置选项 - 添加release.sh脚本用于项目构建和发布 - 移除Database枚举类中多余的注释 这些修改使得项目能够支持SQLite轻量级数据库作为MySQL的替代方案,同时改进了数据库相关的错误提示和用户体验。 #2
1 parent dc7b6eb commit f419728

File tree

6 files changed

+117
-6
lines changed

6 files changed

+117
-6
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@
5555
<scope>runtime</scope>
5656
</dependency>
5757

58+
<dependency>
59+
<groupId>org.xerial</groupId>
60+
<artifactId>sqlite-jdbc</artifactId>
61+
<version>3.45.2.0</version>
62+
</dependency>
63+
64+
5865
<!-- Jackson JSON 解析核心 -->
5966
<dependency>
6067
<groupId>com.fasterxml.jackson.core</groupId>

scripts/release.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
APP_NAME="ExploitDB"
4+
MAIN_CLASS="xin.ctkqiang.Main"
5+
VERSION="v1.0.0"
6+
RELEASE_DIR="releases/${VERSION}"
7+
OUT_DIR="out"
8+
9+
# 彩色 ASCII 标题(纯 echo)
10+
ascii_banner() {
11+
echo " _____ _ _ _ _ _ "
12+
echo " | ____|_ ___ __ | | ___ (_) |_(_)___| |_ ___ _ __ "
13+
echo " | _| \ \/ / '_ \| |/ _ \| | __| / __| __/ _ \| '__|"
14+
echo " | |___ > <| |_) | | (_) | | |_| \__ \ || (_) | | "
15+
echo " |_____/_/\_\ .__/|_|\___/|_|\__|_|___/\__\___/|_| "
16+
echo " |_| "
17+
}
18+
19+
# 动画函数
20+
wait_animation() {
21+
local MESSAGE=$1
22+
local DOTS=""
23+
24+
echo "$MESSAGE"
25+
for i in 1 2 3; do
26+
DOTS="$DOTS."
27+
echo "$DOTS"
28+
sleep 0.3
29+
done
30+
}
31+
32+
# 步骤开始
33+
ascii_banner
34+
wait_animation "🌸 灵儿正在为你编译 Java 11 项目"
35+
36+
# 清理旧文件
37+
rm -rf $OUT_DIR $RELEASE_DIR
38+
mkdir -p $OUT_DIR
39+
40+
# 编译
41+
find ./src -name "*.java" >sources.txt
42+
javac -source 11 -target 11 -d $OUT_DIR @sources.txt
43+
44+
if [ $? -ne 0 ]; then
45+
echo "❌ 编译失败了!检查一下语法哦~"
46+
exit 1
47+
fi
48+
49+
wait_animation "🎀 编译完成,开始打包成 JAR"
50+
51+
# 创建 JAR 包
52+
JAR_NAME="${APP_NAME}-${VERSION}.jar"
53+
jar cfe $JAR_NAME $MAIN_CLASS -C $OUT_DIR .
54+
55+
if [ $? -ne 0 ]; then
56+
echo "❌ 打包失败了!可能是入口类路径设置错了~"
57+
exit 1
58+
fi
59+
60+
# 准备 Release 目录
61+
mkdir -p $RELEASE_DIR
62+
mv $JAR_NAME $RELEASE_DIR/
63+
64+
wait_animation "📦 发布结构整理完成"
65+
66+
# Release Summary
67+
echo ""
68+
echo "🎉 Release 打包成功!少女完成度 100%~"
69+
echo "📁 输出目录: $RELEASE_DIR"
70+
echo "📦 文件名: $JAR_NAME"
71+
echo "🔮 Java 版本: $(java -version 2>&1 | head -n 1)"
72+
echo ""
73+
echo "下一步:上传 GitHub Release 页面吧 💖"

src/main/java/xin/ctkqiang/Main.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.util.List;
55
import java.util.Scanner;
66

7+
import xin.ctkqiang.config.Configuration;
78
import xin.ctkqiang.controller.ExploitDbController;
89
import xin.ctkqiang.controller.UserUtil;
10+
import xin.ctkqiang.dto.Database;
911

1012
public class Main {
1113
public static final String VERSION = "1.0";
@@ -23,6 +25,8 @@ public class Main {
2325

2426
private static List<String> allowed = Arrays.asList("csv", "json", "sql");
2527

28+
private static Configuration Config;
29+
2630
private static void PrintBanner() {
2731
System.out.println("===================================");
2832
System.out.println(" " + TITLE + " v" + VERSION);
@@ -35,6 +39,20 @@ public static void main(String[] args) {
3539
try {
3640
Main.PrintBanner();
3741

42+
/**
43+
* 设置数据库模式 ♡
44+
* 可选值请查阅 {@link xin.ctkqiang.dto.Database Database} 枚举类:
45+
* <ul>
46+
* <li>{@link xin.ctkqiang.dto.Database#MYSQL MYSQL} :标准的 MySQL 数据库</li>
47+
* <li>{@link xin.ctkqiang.dto.Database#SQLite SQLite} :轻量级嵌入式数据库</li>
48+
* </ul>
49+
* 如果想用 SQLite,就把这里改成 {@link xin.ctkqiang.dto.Database#SQLite Database.SQLITE}
50+
* 哦~ ✨🤭⚡️🌸🌸🌸
51+
*/
52+
53+
// Main.Config.setDatabaseMode(Database.MYSQL);
54+
Main.Config.setDatabaseMode(Database.SQLITE);
55+
3856
int pages = userUtil.askForPositiveInt("📄 想爬多少页咧~?(建议填个50以上更爽!):");
3957
boolean isExport = userUtil.askForYesNo("💾 要不要顺便导出数据嘞?(支持 .csv/.json/.sql哦)✨:");
4058

src/main/java/xin/ctkqiang/config/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class Configuration {
99
public static final String DB_URL = "jdbc:mysql://localhost:3306/" + DB_NAME
1010
+ "?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false";
1111

12+
public static final String DB_SQLITE_URL = "jdbc:sqlite:ling.sqlite";
13+
1214
public static final String DB_USER = "root"; // 改成你的数据库用户名
1315
public static final String DB_PASSWORD = ""; // 改成你的数据库密码
1416
public static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";

src/main/java/xin/ctkqiang/controller/DatabaseController.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class DatabaseController {
3333
/** 数据库名称 */
3434
protected final static String DB_NAME = Configuration.DB_NAME;
3535

36-
/** 数据库连接URL */
36+
/** MYSQL 数据库连接URL */
3737
protected final static String DB_URL = Configuration.DB_URL;
3838

3939
/** 数据库用户名 */
@@ -45,6 +45,9 @@ public class DatabaseController {
4545
/** 数据库驱动类名 */
4646
protected final static String DB_DRIVER = Configuration.DB_DRIVER;
4747

48+
/** SQLITE 数据库连接URL */
49+
protected final static String DB_SQLITE_URL = Configuration.DB_SQLITE_URL;
50+
4851
private Configuration Config;
4952

5053
/**
@@ -123,13 +126,22 @@ public void CreateTableIfNotExists() {
123126
}
124127

125128
if (dbMode == null) {
126-
System.out.println("⚠️ Unknown database mode: " + mode);
129+
System.out.println("🥴 吃嗯的!这个数据库模式不认识喔:\"" + mode + "\" 妹妹我拒绝连接!");
127130
return;
128131
}
129132

130133
switch (dbMode) {
131134
case SQLITE:
132-
System.out.println("📦 Connect to SQLite database");
135+
// 加载 SQLite JDBC 驱动
136+
Class.forName("org.sqlite.JDBC");
137+
138+
// 构建连接(数据库文件叫 ling.sqlite)
139+
try (Connection conn = DriverManager.getConnection(DatabaseController.DB_SQLITE_URL);
140+
Statement stmt = conn.createStatement()) {
141+
stmt.execute(query);
142+
System.out.println("🎀 SQLite 模式下,表结构初始化好啦!已经准备好可爱的记录了喵~");
143+
}
144+
133145
break;
134146
case MYSQL:
135147
default:
@@ -143,12 +155,12 @@ public void CreateTableIfNotExists() {
143155
DatabaseController.DB_PASSWORD);
144156
Statement stmt = conn.createStatement()) {
145157
stmt.execute(query);
146-
System.out.println("💾 数据表【内容信息】初始化成功");
158+
System.out.println("💾 MySQL 模式下,数据表【内容信息】初始化成功~♡");
147159
}
148160
}
149161

150162
} catch (Exception e) {
151-
System.err.println("❌ 数据表创建失败:" + e.getMessage());
163+
System.err.println("❌ 表创建失败惹呜呜呜呜:妹抖崩坏 > <\n" + e.getMessage());
152164
e.printStackTrace();
153165
}
154166
}

src/main/java/xin/ctkqiang/dto/Database.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public String getValue() {
1414
return value;
1515
}
1616

17-
// 可选: 根据字符串反查 enum(比如传入 "MySQL" 返回 MYSQL 枚举值)
1817
public static Database fromValue(String value) {
1918
for (Database db : values()) {
2019
if (db.value.equalsIgnoreCase(value)) {

0 commit comments

Comments
 (0)