From 811f23475c6aa380ca888fb94bbb1b14612dcfad Mon Sep 17 00:00:00 2001 From: oneao Date: Tue, 17 Mar 2026 21:46:37 +0800 Subject: [PATCH] u --- code/test/.gitignore | 39 +++++++++++++++++++ code/test/.idea/.gitignore | 5 +++ code/test/.idea/encodings.xml | 7 ++++ code/test/.idea/misc.xml | 14 +++++++ code/test/pom.xml | 27 +++++++++++++ code/test/src/main/java/org/example/Main.java | 36 +++++++++++++++++ 6 files changed, 128 insertions(+) create mode 100644 code/test/.gitignore create mode 100644 code/test/.idea/.gitignore create mode 100644 code/test/.idea/encodings.xml create mode 100644 code/test/.idea/misc.xml create mode 100644 code/test/pom.xml create mode 100644 code/test/src/main/java/org/example/Main.java diff --git a/code/test/.gitignore b/code/test/.gitignore new file mode 100644 index 00000000..480bdf52 --- /dev/null +++ b/code/test/.gitignore @@ -0,0 +1,39 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ +.kotlin + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/code/test/.idea/.gitignore b/code/test/.idea/.gitignore new file mode 100644 index 00000000..b58b603f --- /dev/null +++ b/code/test/.idea/.gitignore @@ -0,0 +1,5 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/code/test/.idea/encodings.xml b/code/test/.idea/encodings.xml new file mode 100644 index 00000000..aa00ffab --- /dev/null +++ b/code/test/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/code/test/.idea/misc.xml b/code/test/.idea/misc.xml new file mode 100644 index 00000000..6774fba6 --- /dev/null +++ b/code/test/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/code/test/pom.xml b/code/test/pom.xml new file mode 100644 index 00000000..f4b50f9e --- /dev/null +++ b/code/test/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.example + test + 1.0-SNAPSHOT + + + 8 + 8 + UTF-8 + + + + + + com.microsoft.sqlserver + mssql-jdbc + 6.2.2.jre8 + + + + + \ No newline at end of file diff --git a/code/test/src/main/java/org/example/Main.java b/code/test/src/main/java/org/example/Main.java new file mode 100644 index 00000000..c13a3bdd --- /dev/null +++ b/code/test/src/main/java/org/example/Main.java @@ -0,0 +1,36 @@ +package org.example; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +public class Main { + public static void main(String[] args) { + // ✅ 修改下面的信息 + String url = "jdbc:sqlserver://192.168.118.128:1433;databaseName=master;encrypt=true;trustServerCertificate=true;sslProtocol=TLSv1"; + String user = "sa"; + String password = "root"; // 改成真实密码 + + try { + // 连接数据库 + Connection conn = DriverManager.getConnection(url, user, password); + System.out.println("✅ 成功连接 SQL Server!"); + + // 测试查询版本信息 + Statement stmt = conn.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT @@VERSION AS version"); + while (rs.next()) { + System.out.println("SQL Server 版本: " + rs.getString("version")); + } + + // 关闭资源 + rs.close(); + stmt.close(); + conn.close(); + } catch (Exception e) { + System.out.println("❌ 连接失败: " + e.getMessage()); + e.printStackTrace(); + } + } +}