service层和impl

service层:管理具体的功能的接口,具体业务逻辑层

package com.nz.service;
import java.util.List;
import com.nz.entity.BankAccount;
public interface JDBCService {
    //查
    public List JDBCQuery();
    //新增
    public boolean JDBCAdd(BankAccount bankAccount);
    //新增后查询
    public List JDBCAddQuery(BankAccount bankAccount);
    }

impl层:是继承service,dao层具体的实现类

package com.nz.service.impl;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import com.nz.dao.JDBCDao;
import com.nz.entity.BankAccount;
import com.nz.service.JDBCService;
import com.nz.util.MySQLDriverUtil;
public class JDBCServiceImpl implements JDBCService{
    //创建对象
    JDBCDao jdbcDao = new JDBCDao();
    @Override
    public List JDBCQuery() {
        //初始化反参
        List list = new ArrayList();
        //查
        try {
            list = jdbcDao.JDBCSelect();
            //尝试获取连接 
            Connection connection = MySQLDriverUtil.getConnect();
            //关闭流
            MySQLDriverUtil.flowClose(connection);
            } catch (Exception e) {
                e.printStackTrace();
                }
        return list;
        }
        //新增
    public boolean JDBCAdd(BankAccount bankAccount) {
        try {
            boolean bl = jdbcDao.JDBCInsert(bankAccount);
            //尝试获取连接
            Connection connection = MySQLDriverUtil.getConnect();
            //关闭流
            MySQLDriverUtil.flowClose(connection);
            return true;
            } catch (Exception e) {
                e.printStackTrace();
            }
        return false;
        }
        @Override
        public List JDBCAddQuery(BankAccount bankAccount) { 
            try {
                boolean bl = jdbcDao.JDBCInsert(bankAccount);
                List list = jdbcDao.JDBCSelect();
                return list;
                } catch (Exception e) {
                    e.printStackTrace();
                    }finally{
                        //尝试获取连接
                        Connection connection = MySQLDriverUtil.getConnect();
                        //关闭流
                        MySQLDriverUtil.flowClose(connection);
                        }
            return null;
        }
    }

你可能感兴趣的:(java,servlet,jvm)