⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tgetproductsdao.java

📁 jsp网页
💻 JAVA
字号:
/**
 * 
 */
package com.rfid.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.rfid.global.DbUtil;
import com.rfid.model.TGetProducts;
import com.rfid.model.TInStore;
/**
 * @author yesiwill
 *
 */
public class TGetProductsDAO {

	/**
	 * @param args
	 */
	
	public int insert(TGetProducts getproducts) {
		int result = 0;
		//System.out.print(result);
		Connection conn = DbUtil.getConnection();
		PreparedStatement stmt = null;
		
		String sqlStr = "insert into t_getproducts(order_id,name,number,input_time,input_user,isget) ";
		sqlStr += "values (?,?,?,?,?,?)";

		try {
			stmt = conn.prepareStatement(sqlStr);
			conn.setAutoCommit(false);
			stmt.setInt(1, getproducts.getOrder_id());
			stmt.setString(2, getproducts.getName());
			stmt.setInt(3, getproducts.getNumber());
			stmt.setTimestamp(4, Timestamp.valueOf(new Date().toLocaleString()));
			stmt.setInt(5, getproducts.getInput_user());
			stmt.setInt(6, getproducts.getIsget());
			
			result = stmt.executeUpdate();
			//System.out.print(result);
			conn.commit();
		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} finally {
			try {
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return result;
	}
	
	public int getLastId(){
		int LastId = 0;
		Connection conn = DbUtil.getConnection();
		PreparedStatement stmt = null;
		ResultSet rs = null;
		//TGetProducts getproducts = new TGetProducts();
		
		String sqlStr = "select id from t_getproducts where id >= ALL(select id from t_getproducts)";

		try {
			stmt = conn.prepareStatement(sqlStr);
			conn.setAutoCommit(false);
			rs = stmt.executeQuery();
			conn.commit();
			
			if (rs.next()) {
				LastId = rs.getInt("id");
			}
		} catch (Exception e) {
			try {
				conn.rollback();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} finally {
			try {
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return LastId;
	}
	
	public List getOutProducts() {
		List list = new ArrayList();

		String sqlStr = "select * from t_getproducts where isget=0 order by id";
		Connection conn = DbUtil.getConnection();
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			stmt = conn.prepareStatement(sqlStr);
			conn.setAutoCommit(false);
			rs = stmt.executeQuery();
			conn.commit();

			/* 遍历将rs中的结果插入list中返回 */
			if (rs != null) {
				TGetProducts getproduct = null;
				while (rs.next()) {
					getproduct = new TGetProducts();
					getproduct.setId(rs.getInt("id"));
					getproduct.setName(rs.getString("name"));
					getproduct.setNumber(rs.getInt("number"));
					getproduct.setInput_time(rs.getDate("input_time"));
					getproduct.setOrder_id(rs.getInt("order_id"));
					getproduct.setInput_user(rs.getInt("input_user"));
					list.add(getproduct);
				}
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				rs.close();
				stmt.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return list;
	} 
	

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -