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

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