【Java开源代码栏目提醒】:本文主要为网学会员提供CustomerDao.java,希望对需要CustomerDao.java网友有所帮助,学习一下!
package com.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.form.CustomerForm;
import com.tools.JDBConnection;
/*************************************
版权所有: 吉林省明日科技有限公司
完成日期: 2010-09-15
项目出处: 编程词典
服务社区: www.mingribook.com
学习社区: www.mrbccd.com
*************************************/
public class CustomerDao {
public JDBConnection connection = null;
public CustomerDao() {
connection = new JDBConnection();
}
public boolean operationCustomer(String sql) {
return connection.executeUpdate(sql);
}
public List queryCustomerList() {
List list = new ArrayList();
CustomerForm customerForm = null;
String
sql = "select * from tb_customer order by customer_id desc";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
customerForm = new CustomerForm();
customerForm.setCustomer_id(rs.getInt(1));
customerForm.setCustomer_user(rs.getString(2));
customerForm.setCustomer_tel(rs.getString(3));
customerForm.setCustomer_address(rs.getString(4));
list.add(customerForm);
}
} catch (SQLException e) {
e.printStackTrace();
}
return list;
}
public CustomerForm queryCustomerForm(Integer id) {
CustomerForm customerForm = null;
String sql = "select * from tb_customer where customer_id="+id+"";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
customerForm = new CustomerForm();
customerForm.setCustomer_id(rs.getInt(1));
customerForm.setCustomer_user(rs.getString(2));
customerForm.setCustomer_tel(rs.getString(3));
customerForm.setCustomer_address(rs.getString(4));
}
} catch (SQLException e) {
e.printStackTrace();
}
return customerForm;
}
}