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;
}
}
}
}