SlideShare a Scribd company logo
1 of 6
Download to read offline
Tutorial 3: Accessing the Database
In this tutorial, you will learn how to access the database, retrieve data from one of its table and display the data
on a browser using Java EE in NetBeans IDE.
1. Open NetBeans.
2. Create a new Enterprise Application (refer to Tutorial 1 for the steps). If you have already created one,
then open it.
3. Create the database (refer to Tutorial 2 for the steps). If you have already created the database, then
make the connection by clicking the Services tab. Expand Databases until you come across the database
you have created previously, right-click the database then Connect.
4. At this point, your Enterprise Application Project should have the following files:
a. Entity class (<nameOfTable>.java)
b. Entity class session beans (AbstractFacade.java and <nameOfTableFacade.java)
If you still don't have these files at this point, then refer back to Tutorial 2 and create them.
5. Create the client interface.
a. Right-click the Web Application module (…war) then select Properties.
b. On the Project Properties dialog, click Frameworks from the Categories column, then click the
Add button.
c. In the Add a Framework dialog, select JavaServer Faces then click OK.
d. In the application's Web Application module, expand Web Pages directory and delete index.html
or index.jsp. Make sure that only index.xhtml is left.
6. Create the controller object.
a. In the application's Web Application module, right-click Source Packages -> New -> Java
Package. Type controller as package name then click Finish.
b. Right-click the controller package then select New -> JSF Managed Bean (if you don't find this,
click Other -> JavaServer Faces -> JSF Managed Bean.
c. Type the name of the JSF managed bean, then change the Scope value to Session then click Finish
At the point, your enterprise application should have the following files in its directory:
7. Clean and build the application by right-clicking the project then select Clean and Build from the pop up
menu. You should see a green message that says that clean and build is successful. If the message is in
red, then it means that there are errors in the application and you should correct these.
8. Once the build is successful, click the Run button from the standard toolbar to test the application.
You should read something about Facelets on the browser of your desktop, like as follows:
9. Retrieve data from the table and display the data on the browser.
a. Place a form on your JSF (index.xhtml).
b. From the JSF Palette, drag a JSF Data Table From Entity object. If the Palette window is not
displayed, Click Window -> Palette from the menu bar or Window -> IDE Tools -> Palette. This
Palette should be displayed on the right side of the IDE screen.
c. You should see some JSF tags embedded in the body section of your index.xhtml file. These tags
would read as follows:
Drag this object
towards index.xhtml
body section.
10. Add a new method in your controller that would display all records from the table.
a. Right-click the body of the controller class and select Insert Code -> Call Enterprise Bean.
b. Expand your ejb directory and select the appropriate …Façade file.
c. Add the method that would call the findAll() method from the session bean. Your controller code
should look like as follows:
Add this table attribute
if you want your table
to have borders.
d. Correct any errors (if there are any) by importing the necessary packages to gain access to the
library files you need – java.util.List and your entities package that contains your entity class.
e. Clean and Build, then run your program. You should see the following output on your browser.
Add this method to the controller
code. Make sure you use the correct
entity name (the one you have in
your entities package – in the ejb).
Your Project Directory
should have the following
files in it.

More Related Content

What's hot

How to debug a fast formula
How to debug a fast formulaHow to debug a fast formula
How to debug a fast formulaFeras Ahmad
 
Visual studio ide componects dot net framwork
Visual studio ide componects dot net framworkVisual studio ide componects dot net framwork
Visual studio ide componects dot net framworkDipen Parmar
 
7200342 cognos-report-studio
7200342 cognos-report-studio7200342 cognos-report-studio
7200342 cognos-report-studiosarovar1
 
7 Methods to Solve "You don't have appropriate permission to perform this ope...
7 Methods to Solve "You don't have appropriate permission to perform this ope...7 Methods to Solve "You don't have appropriate permission to perform this ope...
7 Methods to Solve "You don't have appropriate permission to perform this ope...DataNumen, Inc.
 
Odi 11g master and work repository creation steps
Odi 11g master and work repository creation stepsOdi 11g master and work repository creation steps
Odi 11g master and work repository creation stepsDharmaraj Borse
 
Make a Password storage using Excel
Make a Password storage using ExcelMake a Password storage using Excel
Make a Password storage using ExcelMahmudur Rahman
 
Selenium ide material (2)
Selenium ide material (2)Selenium ide material (2)
Selenium ide material (2)Sriram Angajala
 
External View Creation Guide
External View Creation GuideExternal View Creation Guide
External View Creation GuideAbhishek Agrawal
 
An invisible oracle bug
An invisible oracle bugAn invisible oracle bug
An invisible oracle bugsantosh challa
 

What's hot (15)

How to debug a fast formula
How to debug a fast formulaHow to debug a fast formula
How to debug a fast formula
 
Test case
Test caseTest case
Test case
 
Visual studio ide componects dot net framwork
Visual studio ide componects dot net framworkVisual studio ide componects dot net framwork
Visual studio ide componects dot net framwork
 
7200342 cognos-report-studio
7200342 cognos-report-studio7200342 cognos-report-studio
7200342 cognos-report-studio
 
Setting up an odi agent
Setting up an odi agentSetting up an odi agent
Setting up an odi agent
 
7 Methods to Solve "You don't have appropriate permission to perform this ope...
7 Methods to Solve "You don't have appropriate permission to perform this ope...7 Methods to Solve "You don't have appropriate permission to perform this ope...
7 Methods to Solve "You don't have appropriate permission to perform this ope...
 
tPlan
tPlantPlan
tPlan
 
Odi 11g master and work repository creation steps
Odi 11g master and work repository creation stepsOdi 11g master and work repository creation steps
Odi 11g master and work repository creation steps
 
@Prompt
@Prompt@Prompt
@Prompt
 
Make a Password storage using Excel
Make a Password storage using ExcelMake a Password storage using Excel
Make a Password storage using Excel
 
Selenium ide material (2)
Selenium ide material (2)Selenium ide material (2)
Selenium ide material (2)
 
Chrome devtool
Chrome devtoolChrome devtool
Chrome devtool
 
External View Creation Guide
External View Creation GuideExternal View Creation Guide
External View Creation Guide
 
An invisible oracle bug
An invisible oracle bugAn invisible oracle bug
An invisible oracle bug
 
Attach
AttachAttach
Attach
 

Similar to Tutorial 3 accessing the database

Oracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning TutorialOracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning TutorialRakesh Gujjarlapudi
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB MahmoudOHassouna
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxkeilenettie
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Amit Singh
 
Create software builds with jazz team build
Create software builds with jazz team buildCreate software builds with jazz team build
Create software builds with jazz team buildBill Duncan
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universitylhkslkdh89009
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part IIMichael Fons
 
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I  GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I MatthewTennant613
 
( 5 ) Office 2007 Create A Business Data Catolog
( 5 ) Office 2007   Create A Business Data Catolog( 5 ) Office 2007   Create A Business Data Catolog
( 5 ) Office 2007 Create A Business Data CatologLiquidHub
 
Developing RIA Web Applications with Oracle ADF.pdf
Developing RIA Web Applications with Oracle ADF.pdfDeveloping RIA Web Applications with Oracle ADF.pdf
Developing RIA Web Applications with Oracle ADF.pdfsheriframadan18
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in JavaMichael Fons
 

Similar to Tutorial 3 accessing the database (20)

Components lab
Components labComponents lab
Components lab
 
Components lab
Components labComponents lab
Components lab
 
Oracle ADF 11g Tutorial
Oracle ADF 11g TutorialOracle ADF 11g Tutorial
Oracle ADF 11g Tutorial
 
Oracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning TutorialOracle ADF 11g Skinning Tutorial
Oracle ADF 11g Skinning Tutorial
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
Oracle EBS 12.1.3 : Integrate OA Framework BC4J components within java concur...
 
Create software builds with jazz team build
Create software builds with jazz team buildCreate software builds with jazz team build
Create software builds with jazz team build
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
Metamorphosis from Forms to Java: A technical lead's perspective, part II
Metamorphosis from Forms to Java:  A technical lead's perspective, part IIMetamorphosis from Forms to Java:  A technical lead's perspective, part II
Metamorphosis from Forms to Java: A technical lead's perspective, part II
 
Installation
InstallationInstallation
Installation
 
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I  GEIT 3341  DATABASE I  LAB 2  GEIT 3341 Database I
GEIT 3341 DATABASE I LAB 2 GEIT 3341 Database I
 
( 5 ) Office 2007 Create A Business Data Catolog
( 5 ) Office 2007   Create A Business Data Catolog( 5 ) Office 2007   Create A Business Data Catolog
( 5 ) Office 2007 Create A Business Data Catolog
 
Lab3 RTC Source Control
Lab3 RTC Source ControlLab3 RTC Source Control
Lab3 RTC Source Control
 
Tutorial for netbeans
Tutorial for netbeansTutorial for netbeans
Tutorial for netbeans
 
Developing RIA Web Applications with Oracle ADF.pdf
Developing RIA Web Applications with Oracle ADF.pdfDeveloping RIA Web Applications with Oracle ADF.pdf
Developing RIA Web Applications with Oracle ADF.pdf
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
Applications lab
Applications lab Applications lab
Applications lab
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Tutorial 3 accessing the database

  • 1. Tutorial 3: Accessing the Database In this tutorial, you will learn how to access the database, retrieve data from one of its table and display the data on a browser using Java EE in NetBeans IDE. 1. Open NetBeans. 2. Create a new Enterprise Application (refer to Tutorial 1 for the steps). If you have already created one, then open it. 3. Create the database (refer to Tutorial 2 for the steps). If you have already created the database, then make the connection by clicking the Services tab. Expand Databases until you come across the database you have created previously, right-click the database then Connect. 4. At this point, your Enterprise Application Project should have the following files: a. Entity class (<nameOfTable>.java) b. Entity class session beans (AbstractFacade.java and <nameOfTableFacade.java) If you still don't have these files at this point, then refer back to Tutorial 2 and create them. 5. Create the client interface. a. Right-click the Web Application module (…war) then select Properties. b. On the Project Properties dialog, click Frameworks from the Categories column, then click the Add button.
  • 2. c. In the Add a Framework dialog, select JavaServer Faces then click OK. d. In the application's Web Application module, expand Web Pages directory and delete index.html or index.jsp. Make sure that only index.xhtml is left. 6. Create the controller object. a. In the application's Web Application module, right-click Source Packages -> New -> Java Package. Type controller as package name then click Finish. b. Right-click the controller package then select New -> JSF Managed Bean (if you don't find this, click Other -> JavaServer Faces -> JSF Managed Bean. c. Type the name of the JSF managed bean, then change the Scope value to Session then click Finish
  • 3. At the point, your enterprise application should have the following files in its directory: 7. Clean and build the application by right-clicking the project then select Clean and Build from the pop up menu. You should see a green message that says that clean and build is successful. If the message is in red, then it means that there are errors in the application and you should correct these. 8. Once the build is successful, click the Run button from the standard toolbar to test the application.
  • 4. You should read something about Facelets on the browser of your desktop, like as follows: 9. Retrieve data from the table and display the data on the browser. a. Place a form on your JSF (index.xhtml). b. From the JSF Palette, drag a JSF Data Table From Entity object. If the Palette window is not displayed, Click Window -> Palette from the menu bar or Window -> IDE Tools -> Palette. This Palette should be displayed on the right side of the IDE screen. c. You should see some JSF tags embedded in the body section of your index.xhtml file. These tags would read as follows: Drag this object towards index.xhtml body section.
  • 5. 10. Add a new method in your controller that would display all records from the table. a. Right-click the body of the controller class and select Insert Code -> Call Enterprise Bean. b. Expand your ejb directory and select the appropriate …Façade file. c. Add the method that would call the findAll() method from the session bean. Your controller code should look like as follows: Add this table attribute if you want your table to have borders.
  • 6. d. Correct any errors (if there are any) by importing the necessary packages to gain access to the library files you need – java.util.List and your entities package that contains your entity class. e. Clean and Build, then run your program. You should see the following output on your browser. Add this method to the controller code. Make sure you use the correct entity name (the one you have in your entities package – in the ejb). Your Project Directory should have the following files in it.