0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

glassfishでMySQLを使う

0
Posted at

glassfishでMySQLをJDBCコネクションプールに登録する際に発生したエラーについて。

データソースのクラス名を変更する

glassfishのコネクションプール作成画面でMySQLを選択すると、設定画面でデフォルト表示されるMySQLドライバのクラス名がcom.mysql.jdbc.jdbc2で始まる旧タイプのクラス名となっており、以下のような例外が発生します。

java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlDataSource

この問題は現行のドライバに対応したcom.mysql.cjで始まるクラス名を使用することで解消されます。
例えば、リソースタイプとしてjavax.sql.DataSourceを使用する場合にはcom.mysql.cj.jdbc.MysqlDataSourceを指定してください。

データベースのURLを変更する

リソースタイプとしてjavax.sql.DataSourceを使用する場合、ホスト名、データベース名、ユーザ名、パスワードを設定すれば接続できることになっていますが、以下のような例外が発生する場合があります。

jakarta.resource.spi.ResourceAllocationException: Connection could not be allocated because: Cannot open file:C:\denv\glassfish7\glassfish\domains\domain1/config/keystore.jks [Keystore was tampered with, or password was incorrect]

これはMySQLがSSL接続に対応していないことが原因のようで、Additional PropertiesタブでURLプロパティを追加し、jdbc:mysql://localhost:3306/[データベース名]?useSSL=falseと記述することで回避できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?