Skip to main content

[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: Thu, 25 Apr 2024 01:13:10 +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=ux6Z2BWERICEpevrvjieAnyhRMaQKzL7Ezc3OmGDUH4=; b=ceaX4ePGPTbpuJHhAQDBImfW2avDyh5lFOMSWODxYna8GcHe7TJYk8uT7Hol1jjJJlW2LuL+zFQ3lWDErl1CGOiSKR70+WajRNn22YCNe1RHwocFb+nbRSVl4h6RVYUUH46ZhBzvOGUOUnOSt8sBsrag9e9zcud7s0FN+C0q4hNwnb0NLiFmdjm1gYtJa/oRPd7kzIwAXC/Ry13iE0SrVyChRtITSmaDCY9B1roXsRS656kVb4zNsFrulBYwK9FKjfWd3z1PVTa1pDo0fBb/NEuUgeihMTXRicqPns69keplg7fyW2saTWduNi+B41Uiy+hM8UzDcoNTAHU3pqgjwA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ivctQfTXIucP4rbUL7Nun4Q4pvP/GgdeKOl+5CR2vvbCuaNGw5xMjZdVEzct5PFP1nAnDBAbT6iWeRD/IuIpvNbld8pDiveZsefzeJrFyhRAnc0H98JTe31RMLbq220RwmR1eeft08bYkwibrvl1HnQHQqJRBY32vPN48rslXh/x3VBPAz0LwgncV+KwXol2VBR7/D6vVDtEigUPfIGVGDa+GagYhpL0ZLuHBeIw/lShVzpmS6s7hRSqfdw7q+zJgDmIvn+JPHy54EJEBcLNnXYbyGLJICSqgf9UqhjU5CPOIOpnp81a62cnR2vQy87YtxvqhWtX9mzXFA/IoiP1Wg==
  • 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=ba756eaa-3d56-4754-9766-855d99c5f16a;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-25T00:45:33Z;MSIP_Label_a7295cc1-d279-42ac-ab4d-3b0f4fece050_SiteId=a19f121d-81e1-4858-a9d8-736e267fd4c7;
  • Thread-index: AQHala5wbjXaEz077kKB65ivaP4PxbF26ttAgADXxQCAAGXFoA==
  • Thread-topic: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby

Hi

> Class name is wrong or classpath is not set for : 
> com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource Please check the server.log for more details.

Oops, I may have forgotten to mention something simple: placing the JDBC driver under the lib is to add it to the classpath, so DAS(GlassFish) restart is required.

> And about the step 4 referring these code snippets in which .java file should I refer them? 

It is simply example of how to reference the JDBC resource within your Jakarta EE application deployed to GlassFish. It is not a specific Java file.

> And this ":" at the final of the code snippet is a ";" or "}" to finish the if block?

No. It indicates that the description of any process would continue after that.

Regards,
Hiroki

-----Original Message-----
From: Victor Gimenez <victor.gimenez@xxxxxxxxxxxx> 
Sent: Thursday, April 25, 2024 3:41 AM
To: glassfish-dev@xxxxxxxxxxx
Cc: Sawamura, Hiroki/澤村 大輝 <sawamura.hiroki@xxxxxxxxxxx>
Subject: Re: [glassfish-dev] How to use Glassfish with MySQL or any database instead of Apache Derby

Hello Hiroki! Thanks for your response,



I did the steps 1, 2 and 3 successfully obtaining as return:

```
JDBC connection pool mysql-pool created successfully.
Command create-jdbc-connection-pool executed successfully.
```

Only the connection check with ping returned me:
```
CLI031: Warning: Option "target" is obsolete and will be ignored.
CLI031: Warning: Option "target" is obsolete and will be ignored.
remote failure: Ping Connection Pool failed for org.glassfish.resourcebase.resources.api.PoolInfo@bad58506[jndiName=mysql-pool,
applicationName=null, moduleName=null].
Class name is wrong or classpath is not set for : 
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource Please check the server.log for more details.
Command ping-connection-pool failed.
```

I don't know what is missing in my configurations or if I forgot to set anything else.

And about the step 4 referring these code snippets in which .java file should I refer them? And this ":" at the final of the code snippet is a ";" or "}" to finish the if block?


Thank you,


In 2024-04-24 02:56, Hiroki Sawamura (Fujitsu) wrote:
> 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

Back to the top