Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.neu.edu.DAO; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.dbutils.DbUtils; /** * * @author danis */ public class DAO { private String driver; private String dburl; private String dbuser; private String dbpassword; public DAO() { driver = "com.mysql.jdbc.Driver"; dburl = "jdbc:mysql://projectclouddb.c5fzde1wpjxu.us-west-2.rds.amazonaws.com:3306/cloud_project"; dbuser = "awsuser"; dbpassword = "awspassword"; DbUtils.loadDriver(driver); } public Connection getConnection() { Connection conn = null; try { conn = DriverManager.getConnection(dburl, dbuser, dbpassword); } catch (SQLException ex) { Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex); } return conn; } public void close(Connection connection) { if (connection != null) { try { DbUtils.close(connection); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } }