package com.malk.qiwang.utils; import com.baomidou.mybatisplus.generator.FastAutoGenerator; import com.baomidou.mybatisplus.generator.config.rules.DbColumnType; import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Types; public class MPGenerator { // public static void main(String[] args) { // //可以直接去官方文档上查看 // FastAutoGenerator // .create("jdbc:mysql://localhost:3306/invoice_db?useSSL=false&serverTimezone=Asia/Shanghai", // "root", "123456") // .globalConfig(builder -> { // builder.author("LQY") // .disableOpenDir() // .outputDir(System.getProperty("user.dir")+ // "/mjava-qiwang/src/main/java"); // }) // .dataSourceConfig(builder -> // builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> { // int typeCode = metaInfo.getJdbcType().TYPE_CODE; // if (typeCode == Types.SMALLINT) { // return DbColumnType.INTEGER; // } // return typeRegistry.getColumnType(metaInfo); // })) // .packageConfig(builder -> { // builder.parent("com.malk.qiwang") // .controller("Controller") // .service("Service") // .serviceImpl("Service.impl") // .mapper("mapper") // .entity("entity"); // }) // .strategyConfig(builder -> { // builder.addInclude("invoice_library") // .entityBuilder().enableLombok(); // }) // .templateEngine(new VelocityTemplateEngine()) // .execute(); // } // public static void main(String[] args) { // String url = "jdbc:sqlserver://113.45.187.194:1433;"+"databaseName=dingding;"+"encrypt=false;"+"trustServerCertificate=true;"; // // try (Connection conn = DriverManager.getConnection(url, "hgdd", "hgdd@2025")) { // System.out.println("✅ 连接 SQL Server 成功!"); // } catch (Exception e) { // e.printStackTrace(); // } // } public static void main(String[] args) { // MySQL 本地连接配置 String url = "jdbc:mysql://47.103.203.2:3306/invoice_db?useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai"; String username = "root"; String password = "QWhs@12345"; // 加载 MySQL 驱动(JDBC 4.0 后可以省略,但保留更稳妥) try { Class.forName("com.mysql.cj.jdbc.Driver"); } catch (ClassNotFoundException e) { System.out.println("❌ MySQL JDBC 驱动未找到,请检查依赖"); e.printStackTrace(); return; } // 使用 try-with-resources 自动关闭连接 try (Connection conn = DriverManager.getConnection(url, username, password)) { System.out.println("✅ 连接本地 MySQL 数据库成功!"); System.out.println("数据库: invoice_db"); System.out.println("MySQL 版本: " + conn.getMetaData().getDatabaseProductVersion()); } catch (SQLException e) { System.out.println("❌ 连接 MySQL 数据库失败!"); System.err.println("错误代码: " + e.getErrorCode()); System.err.println("错误信息: " + e.getMessage()); e.printStackTrace(); } } }