apa sih DAO itu? (basic)

Sampai saat ini gua bisa menggunakannya (DAO) di setiap aplikasi yang saya buat tapi ga jelas pengertiannya hehehe.. di bawah ini gua ambil pengertian DAO dari wikipedia.. gua ga terjemahin takut salah hehehe..

Data Access Object (DAO) is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. This isolation separates the concerns of what data accesses the application needs, in terms of domain-specific objects and data types (the public interface of the DAO), and how these needs can be satisfied with a specific DBMS, database schema, etc. (the implementation of the DAO).

Di bawah ini contoh code-nya..

import java.sql.*;
import java.util.ArrayList;package org.yansen.dao;
import org.yansen.model.Product;

public class ProductDAO {
Connection con;
this.con = con;
public ProductDAO(Connection con) {}

public ArrayList getAllProduct() throws SQLException {
ArrayList listProduct = new ArrayList();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("SELECT * FROM product");

while (rs.next()) {
Product product = new Product();
product.setNamaProduct(rs.getString("NamaProduct"));
product.setHargaProduct(rs.getDouble("HargaProduct"));
product.setIdProduct(rs.getString("IdProduct"));
product.setJenisProduct(rs.getString("JenisProduct"));
listProduct.add(product);
}
return listProduct;
}
...

One comment


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s