実現したいこと
書籍で勉強しています。
MybatisとMySqlの接続ができません。
発生している問題・分からないこと
dockerでローカルにSQLを作成していますが、双方がうまく接続できていません。
エラーメッセージ
error
1> Task :mbGenerator FAILED 2 3FAILURE: Build failed with an exception. 4 5* What went wrong: 6Execution failed for task ':mbGenerator'. 7> Communications link failure 8 9 The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. 10 11* Try: 12> Run with --stacktrace option to get the stack trace. 13> Run with --info or --debug option to get more log output. 14> Run with --scan to get full insights. 15> Get more help at https://help.gradle.org. 16 17BUILD FAILED in 22s 181 actionable task: 1 executed 19
該当のソースコード
kotlin
1<?xml version="1.0" encoding="utf-8" ?>2<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD3 MyBatis Generator Configuration 1.0//EN"4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" >5<generatorConfiguration>6 <classPathEntry 7 location="\Users\****\.gradle\caches\modules-2\files-2.1\mysql\mysql-connector-java\8.0.29\16bfffda393ac4fe56f0985f1f035b37d3fc48f\mysql-connector-java-8.0.29.jar"/>8 <context id="MySQLTables" targetRuntime="MyBatis3Kotlin">9 <plugin type="org.mybatis.generator.plugins.MapperAnnotationPlugin"/>10 <commentGenerator>11 <property name="suppressData" value="true"/>12 </commentGenerator>13 <jdbcConnection 14 driverClass="com.mysql.cj.jdbc.Driver"15 connectionURL="jdbc:mysql://172.18.0.2:3306/example2"16 userId="root"17 password="mysql">18 <property name="nulCatalogMeansCurrent" value="true"/>19 </jdbcConnection>20 <javaModelGenerator 21 targetPackage="database"22 targetProject="src/main/kotlin">23 </javaModelGenerator>24 <javaClientGenerator 25 targetPackage="database"26 targetProject="src/main/kotlin">27 </javaClientGenerator>28 <table tableName="user"/>29 </context>30</generatorConfiguration>
docker
1version: '3.8'2 3services:4 db:5 platform: linux/amd64 6 container_name: db 7 image: mysql:8.0.29 8 ports:9 - 4306:3306 10 environment:11 MYSQL_ROOT_PASSWORD: mysql 12 TZ: Asia/Tokyo #time-zoneの指定. 日本時間(東京)に設定13 command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 14 volumes:15 - ./db/data:/var/lib/mysql 16 - ./db/my.cnf:/etc/mysql/cont.d/my.cnf 17 - ./db/sql:/docker-entrypoint-initdb.d
試したこと・調べたこと
上記の詳細・結果
com.mysql.jdbc.Driverがサポートされてないとの記事をみて、com.mysql.cj.jdbc.Driverに変更をしました。そのほかの設定はさわっていません。
補足
特になし

0 コメント