package addrbook;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class AddrBean {

	Connection conn = null;
	PreparedStatement pstmt = null;
	
	String jdbc_driver = "oracle.jdbc.driver.OracleDriver";
	String jdbc_url = "jdbc:oracle:thin:@168.126.146.45:1521:orcl";
	
	void connect() {
		try {
			Class.forName(jdbc_driver);
			
			conn = DriverManager.getConnection(jdbc_url,"20172302","981220");
			
		}catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	void disconnect() {
		
	}
	
	public ArrayList<AddrBook> getDBList(){
		
		connect();
		ArrayList<AddrBook> datas = new ArrayList<AddrBook>();
		
		String sql = "select * from addr_member order by id desc";
		try {
			pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while(rs.next()) {
				AddrBook addrbook = new AddrBook();
				
				addrbook.setNumber(rs.getInt("number"));
				addrbook.setId(rs.getString("id"));
				addrbook.setName(rs.getString("name"));
				addrbook.setBirth(rs.getString("birth"));
				addrbook.setTel(rs.getString("tel"));
				addrbook.setEmail(rs.getString("email"));
				addrbook.setMemo(rs.getString("memo"));
			}
		}
		
		return datas;
	}
}
