Setting up Datasource in Wildfly 10 Application Server

0
546

As part and continuation of the tutorial/project I started in my last post (Car Rental Application with Wildfly Server and Java EE). One of the essential parts of the tutorial/project is a data source which is a name given to the connection set up to a database from a server.

You can watch out for the post where I will create the database in PostgreSQL database Server. I have a Postgres database with name rentalDB. To create a data source, you have to pay attention to the following steps:

  • Download Postgresql driver, I downloaded Postgresql-9.4.1210.jar. If it is zipped, unzip and extract to {wildfly home}/standalone/deployments folder.
  • Fire up the server, you can start it from Netbeans if you have added Wildfly server to Netbeans. If not, open the bin folder in the wildfly home and click on standalone.bat to start the server. Directions on how to configure the Server will soon be up here.
  • Open your browser, go to localhost:8050 or localhost:9990 (it might not be the same port in your own context).

 

  • By now, this file PostgreSQL-9.4.1210.jar.deployed must have been generated in the deployment folder. It signifies that the Postgresql driver has been successfully deployed.
  • When the mangement interface opens, navigate to Configurations tab -> Subsystems -> Datasources -> Non-XA -> click on new.
  • The Datasource subsystem allows you to create and configure data sources and manage JDBC database drivers. Non-XA data sources are used for applications which do not use transactions or applications which use transactions with a single database and  XA datasources, which are used by applications whose transactions are distributed across multiple databases.

 

  • The next windows bring up a list of options, Choose PostgreSQL Datasource and proceed.

 

  • In the next window, input the name and JNDI name. For this tutorial/project, I used rentalDB as name and java:/rentalDB as JNDI name. Click on next and proceed.

 

  • In the next window is where you specify the PostgreSQL driver to use. click on the specify driver tab and choose the PostgreSQL driver that was deployed earlier. Click on next to proceed.

 

  • In the next window, confirm the connection URL and security credentials. The connection URL to our database is JDBC:PostgreSQL://localhost:5432/rentalDB.
  • The next window shows the summary of all our inputs, confirm that all is correct and click on finish.
  • Go back to Configurations tab -> Subsystems -> Datasources -> Non-XA to confirm the addition of our new data source.

 

  • Click on the new rentalDS data source and choose a view. Go to the connection tab, click on test connection to confirm that our exercise really worked.
  • Finally, Open the service tab on the Netbeans IDE window. expand the wildfly server resource tab, under data source you will see the rentalDB already added. In case it is missing, highlight the data source and refresh.

 

We have finally created a data source for our tutorial/project. We can now proceed to create the EJB Module.

To Instal and setup WildFly Application Server, refer to this POST.

LEAVE A REPLY

Please enter your comment!
Please enter your name here