JAKARTA EE FOR JUNIOR DEVELOPERS - Lesson 2 Environment Setup (Part 2)

 


INTRODUCTION
In this second part, we will complete the setup, and more specifically, we will connect the Wildfly Server and NetBeans to the database. This way, we won't need to leave NetBeans, as we can perform all the necessary actions directly within the IDE.

CREATING A DATABASE

I have chosen to install the PostgreSQL database. In addition to being free, PostgreSQL is also production-ready, which means you are very likely to encounter it in companies that maintain custom applications either internally or in the cloud.

All the steps on how to install and create a new database named JakartaEEDB are described in detail in the free course PostgreSQL Lesson 1 - PostgreSQL Installation and Database Creation.


The next step is to download the Java Driver that will allow us to connect the Wildfly Server to the JakartaEEDB database. We go to the Download pgJDBC site and download the latest driver.


CONNECT WILDFLY TO DATABASE
To be able to connect Wildfly to the JakartaEEDB database, we need to install the PostgreSQL driver in Wildfly. This process is very simple. Just move the driver you downloaded into the deployments folder of Wildfly.


Now, start Wildfly from within NetBeans.



Now that Wildfly is up and running, we need to configure the connection using the Wildfly Admin Web Console. Right click on the Wildfly Server and click on the option View Admin Console.



Enter your credentials - username and password you setup during Wildfly installation.



Click on the Configuration and then Subsystems -> Datasources & Drivers -> Datasources and finally click on the add icon.

Choose to create a Datasource


Now we need go through some very simple steps. On the first step we need to choose the type of database we are trying to connect to. In our case this is PostgreSQL.


On the second step, we just accept the default names which describe the name of the connection. In simple terms, we will use the JNDI name later in our code, to connect to the database.


This step is kind of tricky. On the Driver Name input box do not accept the default name. Just click on the down arrow and pick the driver that you have deployed on the Wildfly. Click Next to continue to the next step.





On this step, make sure that on the Connection URL you type the name of the database keeping the rest of the URL as it is. Also, we need to insert the username and the password of the admin postgreSQL account. Click the Next button to continue to the next step.



Time to verify that we have done everything right. Click on the TestConnection button. You should see a Success Message on your screen. Click the Next button.



On this last screen, we just see a summary of all of our options. We do not have to do any further modifications at this point. Our connection to the database has been completed. Just click the Finish button and on the next screen click on the Close button.




We can now see our new connection under the Datasource column. At this point, you need to click on the Reload Required to restart the server.


As far configuring the Wildfly goes, we are done creating a JDBC connection to the database and we are ready from the next Jakarta EE for Junior Developers lesson to start our programming lessons.

Now let's configure a connection to the JakartaEEDB within NetBeans. In that way, we will be able to run queries or check our tables without leaving our IDE.

Under the Services tab, right click on Databases and choose the option New Connection.

On the New Connection Wizard window, click the arrow and choose PostgreSQL for the type of the Driver. Then you click the Add button and point to the directory where you have downloaded the postgreSQL java driver. Do not add the driver from the deployment folder of the Wildfly because that it will not work.


We need to enter the credentials for the database along with the name of the database we are trying to connect. If all the information has been entered correctly, by clicking the Test Connection we should get a Connection Succeeded message. Click Next to proceed to the next step.


On the Select Schema choose the public schema and click on Next.


On this last step, accept the suggested input connection name and click on Finish.


We now have a successful connection to the database within NetBeans. In future lessons, we will using this connection to run queries or to just investigate the relationships among the the tables.


Congratulations! You environment is ready now and starting from the next lesson we will investigate the Jakarta EE Persistence documentation.

full-width

Post a Comment

0 Comments