# VSCode-JDBC-MySQL **Repository Path**: QMMMS/vscode-jdbc-mysql ## Basic Information - **Project Name**: VSCode-JDBC-MySQL - **Description**: 在VSCode中使用Java的JDBC连接MySQL数据库 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-06-22 - **Last Updated**: 2023-06-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # VSCode+JDBC+MySQL配置 在VSCode中使用Java的JDBC连接MySQL数据库 配置成功的案例,留存一份。 ## 文件结构 在`src`文件夹中放置Java程序源代码,配置文件`database.properties`中的MySQL数据库登录密码需要自己设置。 在`lib`文件夹中放置MySQL提供的jar包。 ## 配置方法 ### 1.安装MySQL 在[MySQL社区版下载界面](https://dev.mysql.com/downloads/)选择MySQL Installer for Windows,进入后选择大的安装包下载。安装时按照默认就行。 **Windows中打开服务**:`net start mysql80` **Windows中关闭服务**:`net stop mysql80` mysql80是安装MySQL在windows服务界面配置的服务名,默认mysql80,如果权限不够Win+X,点击终端管理员。 ### 2.导入university数据库 MySQL数据库基本操作不在本配置方法之内,可以参考[这个](https://gitee.com/QMMMS/reading-notes/blob/main/%E8%80%81%E6%9D%9C%20MySQL/note.md) 导入所需的文件在[这里](https://gitee.com/QMMMS/reading-notes/tree/main/%E3%80%8A%E6%95%B0%E6%8D%AE%E5%BA%93%E7%B3%BB%E7%BB%9F%E6%A6%82%E5%BF%B5%E3%80%8B/SQL) - 下载好文件 - 登录MySQL - 创建数据库 - 使用命令`source <不带中文的文件路径名>` 导入SQL文件 ### 3.下载MySQL JDBC驱动 首先查看自己的MySQL版本,在登录之后会显示: ``` PS C:\Users\15951> mysql -uroot -p Enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.33 MySQL Community Server - GPL Copyright (c) 2000, 2023, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> ``` 可以看到作者的MySQL版本是8.0.33,再到MySQL的下载界面去找: 在[MySQL社区版下载界面](https://dev.mysql.com/downloads/)选择[Connector/J](https://dev.mysql.com/downloads/connector/j/),对应最新的MySQL版本驱动选择Platform Independent操作系统,Windows系统选择 ZIP 包下载。对应历史版本的MySQL版本驱动在Archives页面中选择。 解压之后把jar包放在`lib`文件夹中。 ### 4.修改配置与运行 在VSCode中打开项目,配置文件`database.properties`中的MySQL数据库登录密码需要自己设置,运行`App.java`吧! ## 附图 ![](./img/JDBC.png) ![](./img/API.png) ![](./img/DAO.png)