title: Manage connection database with jdbc in jsf
body: <p>Hello please help me with this:</p>
  
  <p>I need know as manage connection in jsf.
  I use JSF 1.1 and use JDBC.</p>
  
  <p>My project has a structure MVC.
  My connection is gets from a Datasource.</p>
  
  <p>Question 1:
  Should I create in a package my connection factory class.
  Question 2:
  Where is correct managed commit and rolback in dao, businesslogig, backingbean package?
  Question 4:
  Where is correct managed open and close connection in dao, businesslogig, backingbean package?</p>
  
  <p>My connection factory class is this below</p>
  
  <pre><code>public class ConexionDB {
  private static Connection connection = null;
  private static  DataSource dataSource=null;
  
  private static void setupDataSource() throws IOException, NamingException {
      Propiedades propiedades = new Propiedades();
      Context  initialContext = new InitialContext();
      dataSource = (DataSource)initialContext.lookup(propiedades.getPropiedad("datasource.JNDI"));
  }
  
  public static Connection getConexion() throws SQLException, IOException, NamingException{
      if (dataSource== null)
          setupDataSource();
      return dataSource.getConnection();
  }}
  </code></pre>
  
  <p>Besides it is advisable to close the connection at every access to data.
  Or handle a single connection per action method managed bean to pass this parameter and make a single close.</p>
  
  <p>Thanks for your help</p>