package com.wu.action;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.wu.Service.CarI;
import com.wu.bean.CarInfo;
import com.wu.util.DbUtil;
import com.wu.util.jsonUtil;

import net.sf.json.JSONArray;

public class CarImpl implements CarI {

	@Override
	public boolean AddCar(CarInfo car) {
		boolean flag = false;
		Connection conn = null;
		PreparedStatement pst = null;
		int result = 0;
		String sql = "insert into carinfo  values(?,?,?)";
		try {
 			conn = DbUtil.getConnection();
			pst = conn.prepareStatement(sql);
			pst.setInt(1, car.getCar_Id());
			pst.setString(2, car.getCar_Type());
			pst.setString(3, car.getCar_user());
			result = pst.executeUpdate();
			conn.setAutoCommit(true);
			DbUtil.closeAll();
			if (result != 0) {
				return true;
			}
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public JSONArray selAll() {
		JSONArray jsonArray = null;
		String sql = "select * from carinfo";
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			conn = DbUtil.getConnection();
			pst = conn.prepareStatement(sql);
			rs = pst.executeQuery();
			jsonArray = jsonUtil.formatRsToJsonArray(rs);
			DbUtil.closeAll();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return jsonArray;
	}

	@Override
	public JSONArray search(int carid) {
		JSONArray jsonArray = null;
		String sql = "select * from carinfo where Car_Id=?";
		Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		try {
			conn = DbUtil.getConnection();
			pst = conn.prepareStatement(sql);
			pst.setInt(1, carid);
			// pst.setString(1, name);
			rs = pst.executeQuery();
			jsonArray = jsonUtil.formatRsToJsonArray(rs);
			DbUtil.closeAll();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return jsonArray;
	}

	@Override
	public boolean Update(CarInfo car) {
		boolean flag = false;
		Connection conn = null;
		PreparedStatement pst = null;
		int result = 0;
		String sql = "update carinfo  set   Car_Type=? , Car_user=?  where Car_Id=? ";
		try {
 			conn = DbUtil.getConnection();
			pst = conn.prepareStatement(sql);
			pst.setString(1, car.getCar_Type());
			pst.setString(2, car.getCar_user());
			pst.setInt(3, car.getCar_Id());
			result = pst.executeUpdate();
			conn.setAutoCommit(true);
			DbUtil.closeAll();
			if (result != 0) {
				return true;
			}
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public ResultSet show() {
		// TODO 自动生成的方法存根
		return null;
	}

}
最近下载更多
171337601  LV9 2022年4月18日
nitama  LV19 2021年5月16日
ericxu1116  LV24 2021年4月26日
rebecca0214  LV2 2021年4月14日
ly_fxm  LV4 2021年1月31日
naixia  LV9 2020年7月8日
芳华林  LV11 2020年6月18日
骄傲的时刻  LV2 2020年5月16日
KING QIN  LV5 2020年5月12日
TerryGaoBo  LV9 2020年4月28日
最近浏览更多
陈小灏  LV18 1月4日
黄志琴  LV1 2024年9月29日
Zeng123qwe 2024年6月1日
暂无贡献等级
微信网友_6906962132258816  LV7 2024年5月15日
WBelong  LV8 2024年4月2日
admin_z  LV22 2024年1月29日
颜菜菜  LV2 2024年1月4日
ncyhhh  LV2 2023年11月26日
飞呀飞呀飞不放  LV7 2023年8月9日
阳光男孩阿葵 2023年7月14日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友