[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby
|
- From: "Hiroki Sawamura (Fujitsu)" <sawamura.hiroki@xxxxxxxxxxx>
- Date: Wed, 24 Apr 2024 05:56:01 +0000
- Accept-language: ja-JP, en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fujitsu.com; dmarc=pass action=none header.from=fujitsu.com; dkim=pass header.d=fujitsu.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oyF7bQ8GNdpjCqc51DLG2qwvwdBAyp2Xd+eusfGiZf0=; b=jP0AcGu+OzWBGTep/REjFkRl6glEhHyZNQPyGTACCb7uoj51NPhvHB73NW17maNR2jrvx2F6MNkiMcTJo+7ANSd3tB/5igMpCxzpt+/IiTI4o3rigVVWR9tRPy2r368ts2pyrpIfyXoEYBDcxRHCLyGdNpMO+tlMC1TMSW3qNrwZccMN5ce8Il5kLhXh9HZDOSNibk3rv5uSBO1V6qC2VrNLZ4xsX3xpmflIS/4ljhogtq8AUDcqkxJBYI2GAYiXRvx+FABkJTsJth1iR9TZ1fjB/hFFtyaC32WeE8oYZdUv0MF+KaDQ/4YQf89600EB+3G1pLNBuEWZXaw5+hAKRg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mDp/rrRGtJFnMbb/GlI1GpqOyTF5s8UJsyrbYGVvPC81xAqeiGCUewsxKmMsQTpQ+ISHrz77nyceVR/ARVKR32trB0V0iodRjE0Qb24d/G1GKuZjcdW7dV5oVb1tUoryJOcc4mO8XwPTlT+QNimPnWbMj8dxq4+KmKWkdgksfPuSdi4nPdkIEzoeKXfjfmbeho77vWYmH1lvdz6xMyxMYS6Upx1VAot7Bxr6VjpmjFNZQXB+LqSp+mBqAYuQYsMJL7bWSy0PoM3Ze17tt1S7ntqNA1GtWXmWzw7gCiPep5I8ZVZQU8bhjMg2BRLXI6i7yLJ6LWJhlqnO855adOqDNw==
- Delivered-to: glassfish-dev@xxxxxxxxxxx
- List-archive: <https://www.eclipse.org/mailman/private/glassfish-dev/>
- List-help: <mailto:glassfish-dev-request@eclipse.org?subject=help>
- List-subscribe: <https://www.eclipse.org/mailman/listinfo/glassfish-dev>, <mailto:glassfish-dev-request@eclipse.org?subject=subscribe>
- List-unsubscribe: <https://www.eclipse.org/mailman/options/glassfish-dev>, <mailto:glassfish-dev-request@eclipse.org?subject=unsubscribe>
- Msip_labels: MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_ActionId=d1695ed6-e307-4ccb-92cf-4194163bec99;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_ContentBits=0;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_Enabled=true;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_Method=Standard;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_Name=FUJITSU-RESTRICTED;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_SetDate=2024-04-24T05:49:01Z;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_SiteId=a19f121d-81e1-4858-a9d8-736e267fd4c7;
- Thread-index: AQHala5wbjXaEz077kKB65ivaP4PxbF26ttA
- Thread-topic: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby
Hi,
There are 4 simple steps to setting up DB with GlassFish.
1. Place JDBC driver in DAS lib dir.
$ mv mysql-connector-java-XXX.jar glassfish7/glassfish/domains/domains/domain1/lib/
2. Create JDBC connection pool.
$ asadmin create-jdbc-connection-pool \
--restype javax.sql.ConnectionPoolDataSource \
--datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource \
--property user=your_username:password=your_password:port=3306:databaseName=your_database_name:serverName=localhost \
mysql-pool
It would be a good to check the connection with ping.
$ asadmin ping-connection-pool mysql-pool
3. Create JDBC resource.
$ asadmin create-jdbc-resource --target server --connectionpoolid mysql-pool jdbc/mysql
4. Refer in your application.
lookup is no longer needed. it can be easily injected and used with jakarta.annotation.Resource annotation.
```java
@Resource(lookup = "jdbc/mysql")
DataSource dataSource;
```
then, describe the operation as follows
```java
java.sql.Connection con = dataSource.getConnection();
if (con.isValid(10)) {
java.sql.Statement stmt = con.createStatement();
java.sql.ResultSet result = stmt.executeQuery("SELECT ID,NAME,PROGRAMMING_LANGUAGE FROM DEV")
:
```
Regards,
Hiroki
-----Original Message-----
From: glassfish-dev <glassfish-dev-bounces@xxxxxxxxxxx> On Behalf Of Victor Gimenez via glassfish-dev
Sent: Wednesday, April 24, 2024 3:44 AM
To: glassfish-dev@xxxxxxxxxxx
Cc: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx>
Subject: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby
Hello there,
I am very new to Glassfish and Jakarta EE which I am learning nowadays, I would like to know what I should do to add MySQL or any database instead of Apache Derby which is configured as the default database server? I am very stuck reading the documentation and without know which files should I configure to add.
Thanks in advance,
--
Victor Borghi Gimenez
Computer Science M.Sc. - Center for Mathematics, Computing and Cognition
- Federal University of ABC (UFABC)
System Analysis and Development Technologist - São Caetano do Sul
College of Technology (FATEC-SCS)
_______________________________________________
glassfish-dev mailing list
glassfish-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/glassfish-dev