[
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
|
Em 2024-04-24 22:13, Hiroki Sawamura (Fujitsu) escreveu:
Hi
Hi Hiroki!
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.
I entered sudo ./asadmin restart-domain to restart the DAS(Glassfish)
and I successfully got this return statement:
```
Waiting finished after 30 ms.
Server instance is stopped, now we wait for the start on localhost:4848
...
Waiting finished after 2,695 ms.
Successfully restarted the domain
Command restart-domain executed successfully.
```
But when I did that ping command the same error persisted, I let the
mysql-connection-java-8.0.21.jar in
/home/victor/Downloads/web-7.0.13/glassfish7/glassfish/domains/domain1/lib/
path.
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.
Ohhhh now it made sense here to me and I realized, I remembered now that
this DataSource dataSource is a variable responsible for getting the
connection number as true or false to create the statement, and after
query, update, delete and so on... In JPA I am using EntityManager em
variable to make the CRUD operations like insert(em.persist), list data
(em.getCriteriaBuilder().createQuery... do you know if I can able to use
also the @Resource annotation above EntityManager em declaration?
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
--
Victor Borghi Gimenez
Computer Science M.Sc. - Center for Mathematics, Computing and Cognition
- Federal University of ABC (UFABC) https://www.ufabc.edu.br/en/
System Analysis and Development Technologist - São Caetano do Sul
College of Technology (FATEC-SCS) https://www.fatecsaocaetano.edu.br/
http://lattes.cnpq.br/4344720857265863
https://www.linkedin.com/in/victor-borghi-giménez-04466666/
https://github.com/VictorGimenez