Java用memcached

package a;

import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;

import net.spy.memcached.MemcachedClient;
import net.spy.memcached.MemcachedConnection;

public class Main {
	private static Connection c = null;
	private static PreparedStatement ps = null;
	private static ResultSet rs = null;
	private static ResultSetMetaData rsmd = null;
	private static MemcachedClient mc = null;

	public static void main(String[] args) {

		ArrayList<HashMap<String, Object>> alhmso = new ArrayList<HashMap<String, Object>>();

		try {
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			c = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databasename=dc2019;Encrypt=false", "sa",
					"dinglin");
			ps = c.prepareStatement(
					"select * from (select *,volume - lag(volume,1,0) over (partition by InstrumentID,tradingday order by InstrumentID asc, tradingday asc , volume asc ) as tmpvol from t_m1 ) as tmp_t1 where  tmpvol <> 0 order by instrumentid asc, tradingday asc, Volume asc\r\n");
			rs = ps.executeQuery();
			// rsmd = rs.getMetaData();
			// int getColumnCount = rsmd.getColumnCount();
			while (rs.next()) {
//				for (int i = 1; i <= getColumnCount; i++) {
//					System.out.print(rs.getString(i) + ",");
//				}
//				System.out.println();

				HashMap<String, Object> hmso = new HashMap<String, Object>();
				hmso.put("id", rs.getInt(1));
				hmso.put("InstrumentID", rs.getString(2));
				hmso.put("TradingDay", rs.getDate(3));
				hmso.put("UpdateTime", rs.getTime(4));
				hmso.put("LastPrice", rs.getBigDecimal(5));
				hmso.put("PreClosePrice", rs.getBigDecimal(6));
				hmso.put("OpenPrice", rs.getBigDecimal(7));
				hmso.put("HighestPrice", rs.getBigDecimal(8));
				hmso.put("LowestPrice", rs.getBigDecimal(9));
				hmso.put("Volume", rs.getInt(10));
				hmso.put("LowerLimitPrice", rs.getBigDecimal(11));
				hmso.put("tmpvol", rs.getInt(12));
				alhmso.add(hmso);
			}
		} catch (Exception e) {
			e.printStackTrace();

		} finally {
			try {
				if (rs != null) {
					rs.close();
					rs = null;
				}
				if (ps != null) {
					ps.close();
					ps = null;
				}
				if (c != null) {
					c.close();
					c = null;
				}

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		Date d = new Date();
		System.out.println(d);
		try {
			mc = new MemcachedClient(new InetSocketAddress("localhost", 11211));
			mc.add("table", 0, alhmso);
			d = new Date();
			System.out.println(d);
			Object o = mc.get("table");
			ArrayList<HashMap<String, Object>> alhmso2 = (ArrayList<HashMap<String, Object>>) o;
			for (HashMap<String, Object> hashMap : alhmso2) {
				System.out.print(hashMap.get("id"));
				System.out.print(hashMap.get("InstrumentID"));
				System.out.print(hashMap.get("TradingDay"));
				System.out.print(hashMap.get("UpdateTime"));
				System.out.print(hashMap.get("LastPrice"));
				System.out.print(hashMap.get("PreClosePrice"));
				System.out.print(hashMap.get("OpenPrice"));
				System.out.print(hashMap.get("HighestPrice"));
				System.out.print(hashMap.get("LowestPrice"));
				System.out.print(hashMap.get("Volume"));
				System.out.print(hashMap.get("LowerLimitPrice"));
				System.out.print(hashMap.get("tmpvol"));
				System.out.println();
			}
			System.out.println(alhmso2.size());
			d = new Date();
			System.out.println(d);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (mc != null) {
				mc.shutdown();
				mc = null;
			}

		}

	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值