diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..1012641 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +DML.java \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml index 3cd3e9d..35f634e 100644 --- a/.idea/dbnavigator.xml +++ b/.idea/dbnavigator.xml @@ -1,16 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/.idea/libraries/junit_4_12.xml b/.idea/libraries/junit_4_12.xml new file mode 100644 index 0000000..fdd6e34 --- /dev/null +++ b/.idea/libraries/junit_4_12.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/libs.xml b/.idea/libraries/libs.xml new file mode 100644 index 0000000..8faa3ad --- /dev/null +++ b/.idea/libraries/libs.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/build.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/db/dbuml.db3 b/db/dbuml.db3 new file mode 100644 index 0000000..1dff0f4 Binary files /dev/null and b/db/dbuml.db3 differ diff --git a/libs/sqlite-jdbc-3.31.1.jar b/libs/sqlite-jdbc-3.31.1.jar new file mode 100644 index 0000000..955f112 Binary files /dev/null and b/libs/sqlite-jdbc-3.31.1.jar differ diff --git a/src/DML.java b/src/DML.java new file mode 100644 index 0000000..978ad96 --- /dev/null +++ b/src/DML.java @@ -0,0 +1,51 @@ +import java.sql.*; + +import org.junit.Test; + +public class DML { + + // 数据库连接字符串 + private static final String URL = "jdbc:sqlite:D:/uml/db/dbuml.db3"; + + @Test + public void create() { + 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" + + ");"; + + // 执行 SQL 语句 + stmt.execute(sql); + + System.out.println("数据表 创建成功"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + + @Test + public void deleteAll() { + try (Connection conn = DriverManager.getConnection(URL); + Statement stmt = conn.createStatement()) { + + // 删除所有记录的 SQL 语句 + String sql = "DELETE FROM xslist"; + + // 执行 SQL 语句 + int result = stmt.executeUpdate(sql); + System.out.println("删除了 " + result + " 条记录"); + + } catch (SQLException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/src/jdbc.java b/src/jdbc.java new file mode 100644 index 0000000..c230765 --- /dev/null +++ b/src/jdbc.java @@ -0,0 +1,43 @@ +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.DatabaseMetaData; + +public class jdbc { + public static void main(String[] args) { + // 定义数据库连接参数 + String driver = "org.sqlite.JDBC"; // SQLite JDBC驱动 + String url = "jdbc:sqlite:./db/dbuml.db3"; // 数据库文件路径 + String user = ""; // SQLite不需要用户名 + String password = ""; // SQLite不需要密码 + + Connection conn = null; + + try { + // 1. 加载注册驱动 + Class.forName(driver); + + // 2. 连接数据库 + conn = DriverManager.getConnection(url, user, password); + + // 3. 输出数据库信息 + if (conn != null) { + DatabaseMetaData metaData = conn.getMetaData(); + System.out.println("数据库名称: " + metaData.getDatabaseProductName()); + System.out.println("数据库版本号: " + metaData.getDatabaseProductVersion()); + System.out.println("数据库URL: " + metaData.getURL()); + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + // 4. 关闭连接 + try { + if (conn != null) { + conn.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/uml.iml b/uml.iml index c90834f..5fe4c4e 100644 --- a/uml.iml +++ b/uml.iml @@ -7,5 +7,7 @@ + +
\ No newline at end of file