From 70cf9de4a5a01efd36ebec1980f1e9a114c25bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E9=91=AB=E6=9D=B0?= <2173036056@qq.com> Date: Fri, 6 Dec 2024 00:45:48 +0800 Subject: [PATCH] test --- .../20241205 maven/20241205 maven.md" | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 "\345\215\242\351\221\253\346\235\260/20241205 maven/20241205 maven.md" diff --git "a/\345\215\242\351\221\253\346\235\260/20241205 maven/20241205 maven.md" "b/\345\215\242\351\221\253\346\235\260/20241205 maven/20241205 maven.md" new file mode 100644 index 0000000..48b3191 --- /dev/null +++ "b/\345\215\242\351\221\253\346\235\260/20241205 maven/20241205 maven.md" @@ -0,0 +1,155 @@ +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044651.png) + +## 一、下载Maven并解压 + +### 1. Maven官网下载地址:[http://maven.apache.org/download.cgi](https://maven.apache.org/download.cgi "http://maven.apache.org/download.cgi") + +截止目前,Maven的最新版为` 3.9.9`,如无特殊需要,直接下载箭头处的最新版压缩包即可。 +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044327.png) + +### 2. 下载后解压,将Maven的压缩包解压到你电脑某个目录 ,如C:\apache-maven-3.9.9 + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044373.png) + + + +## 二、本地仓储配置 + +从中央仓库下载的jar包,都会统一存放到本地仓库中。我们需要配置本地仓库的位置。 + +### 1.新建一个文件夹,名称为“mvn-repository”,假设路径为:C:\apache-maven-3.9.9\mvn-repository + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044362.png) + +### 2.配置setting.xml文件 + +- 在Maven解压文件中打开**conf目录**下的**settings.xml文件** +- ![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044384.png) +- 添加下面这行语句以配置本地仓储位置 + ![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044791.png) + +--------- + + + +## 三、设置阿里云镜像 + +Maven默认访问国外服务器下载包,速度很慢。配置**_阿里云镜像_**下载包会比较快。 + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044053.png) + +打开**conf目录**下的**settings.xml**文件, + +```xml +<-- 在标签下添加标签:--> + + aliyunmaven + * + 阿里云公共仓库 + https://maven.aliyun.com/repository/public + +``` + +-------------- + +## 四,设置IDEA,启用MAVEN相关配置 + + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044286.png) + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044609.png) + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044211.png) +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044911.png) + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044292.png) + +![image.png](https://gitee.com/onesheet/images_backup/raw/master/images/20241204234655.png) + +## 五、设置pom.xml文件 ,配置想要的库的坐标。 + +从maven仓库:[https://mvnrepository.com/](https://gitee.com/link?target=https%3A%2F%2Fmvnrepository.com%2F) 中搜索要的库的名称 ,复制 对应 的XML到pom.xml +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044671.png) + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044166.png) + +![image.png](https://gitee.com/onesheet/images_backup/raw/master/images/20241205000513.png) + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044465.png) + + +![image.png](https://gitee.com/onesheet/images_backup/raw/master/images/20241205000539.png) +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044044.png) + +## 六、测试 + +```java +import java.sql.*; + +public class Mdd { + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + // 创建连接 + String url = "jdbc:mysql://localhost:3306/ok50?useSSL=false&useUnicode=true&characterEncoding=utf8"; + String username = "root"; + String password = "root"; + Connection conn = DriverManager.getConnection(url, username, password); + // 创建stmt对象 + Statement stmt = conn.createStatement(); + + String select = "select * from student"; + ResultSet rs = stmt.executeQuery(select); + // 返回结果 +// if (rs.next()) { + while (rs.next()) { + int stuId = rs.getInt("s_id"); + String name = rs.getString("s_name"); + String birth = rs.getString("s_birth"); + String sex = rs.getString("s_sex"); + System.out.println(stuId + "\t" + name + "\t" + sex+ "\t" + birth); + } + + } +} +``` + +![image.png](https://gitee.com/lu-1021/zhaop/raw/master/lxj/202412060044844.png) + +## 操作 + +```java +package org.example; +import java.sql.*; +public class lxj { + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + Class.forName("com.mysql.cj.jdbc.Driver"); + // 创建连接 + String url = "jdbc:mysql://localhost:3306/librarydb?useSSL=false&useUnicode=true&characterEncoding=utf8"; + String username = "root"; + String password = "123456"; + Connection conn = DriverManager.getConnection(url, username, password); + // 创建stmt对象 + Statement stmt = conn.createStatement(); + + String sql = "select * from student"; + PreparedStatement stml = conn.prepareStatement(sql); + ResultSet rs = stmt.executeQuery(sql); + // 返回结果 +// if (rs.next()) { + while (rs.next()) { + int StudentCode = rs.getInt("StudentCode"); + String Studentname = rs.getString("Studentname"); + String Gender = rs.getString("Gender"); + String Birthday = rs.getString("Birthday"); + String School = rs.getString("School"); + System.out.println(StudentCode + "\t" + Studentname+ "\t" +Gender + "\t" + Birthday+ "\t" +School); + } + + } + } + + +``` + -- Gitee