前提・実現したいこと
仮想サーバー(VirtualBox + CentOS)の中にあるMySQLのテーブルにJava(Spring boot)から接続したい。
発生している問題・エラーメッセージ
プロジェクトを実行しようとすると以下のメッセージが出て接続できません。
全文を掲載しようとしたのですが、とてつもなく長いログのため、teratailに投稿を拒否されましたので重要そうな部分を抜き出しています。
どなたかご教授いただけると幸いです。
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure (中略) org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta-data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure (中略) The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
該当のソースコード
buid.gradle
json
1plugins { 2 id 'org.springframework.boot' version '2.1.5.RELEASE' 3 id 'java' 4} 5 6apply plugin: 'io.spring.dependency-management' 7 8group = 'com.kenta' 9version = '0.0.1-SNAPSHOT' 10sourceCompatibility = '1.8' 11 12repositories { 13 mavenCentral() 14} 15 16dependencies { 17 implementation 'org.springframework.boot:spring-boot-starter-web' 18 testImplementation 'org.springframework.boot:spring-boot-starter-test' 19 compile('org.springframework.boot:spring-boot-starter-thymeleaf') 20 compile('org.springframework.boot:spring-boot-starter-data-jpa') 21 compile ('org.springframework.boot:spring-boot-starter-web') 22 compile 'org.springframework.boot:spring-boot-starter-jdbc' 23 compile 'mysql:mysql-connector-java:5.1.35' 24 compile 'com.jcraft:jsch:0.1.53' 25}
application.properties
(??????はMySqlのユーザー名とパスワード)
spring.jpa.open-in-view=true logging.file=logs/myapp.log logging.level.org.springframework.web=INFO spring.datasource.url=jdbc:mysql://127.0.0.1:3306/${student_directory} spring.datasource.username=${??????} spring.datasource.password=${??????} spring.datasource.driver-class-name=com.mysql.jdbc.Driver
データーベース名 | テーブル名 |
---|---|
student_directory | M_student |
試したこと
エラーメッセージをコピーしてGoogleで調べたところDB名を間違えていないかという指摘をされている方がおりましたので、
terminalから仮想サーバーにログインして確認しました。ですが、このユーザー名とパスワードでterminalからMySQLの該当テーブルを操作することは出来ましたのでテーブルは存在し、操作権限もgrant all で付与できている事を確認済みです。
また、サーバーサイドDBを使わず組み込みメモリ型データベースのH2databaseでは読み書きできる状態です。
他のサイトを参考に見よう見まねで修正しておりましたが手詰まりになりました。
補足情報(FW/ツールのバージョンなど)
OS:macOS
仮想サーバー:VirtualBox,CentOS6
仮想サーバーの構築にはvagrantを使用。
DB:MySQL
IDE:STS(eclipse)
言語:java8,Spring FrameWork
回答1件
あなたの回答
tips
プレビュー