Connect to database using jsf

How do I connect to the database(MYSQL) in connection bean using JSF to retrieve its contents. Also please let me know how do I configure the web.xml file?


Here is a very good tutorial on how to use DAO with JSF in the best way:

If you are using JSF, that website can be a good place to find solutions for common problems. There are great and complete examples.

Anyway, JSF is a framework that manages the view and the controller layers. For the model layer and the access to a database there are not big difference if you use JSF or any other java web framework that manages the view/controller part of your application.

To get connected to mysql:

public void open() {
        try {
            String databaseName = "custom";
            String userName = "root";
            String password = "welcome";

            String url = "jdbc:mysql://localhost/" + databaseName;

            connection = DriverManager.getConnection(url, userName, password);
        } catch (Exception e) {
            System.out.println("Not able to connect");

In this case there is nothing to change in web.xml.But you to add this in pom.xml

            <groupId>groupId = mysql</groupId>


This was working successfully.

Need Your Help

remove : prolog

prolog sicstus-prolog

I am trying to compile from "Computational Intelligence book" which solves the constraint satisfaction problem. I want to use this as a base to solve crossword puzzle generator.

the meaning of kinds of curve in PDG

context-free-grammar frama-c

I want know what's the meaning of a curve or arc in PDG.