java - Writing to KDB using qJava -
i'm not kdb ( in case question sounds stupid). i'm trying use kdb ( disk not memory) load data database. i've asked question upserts , figured how upsert console , save disk
q)dspricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$()) q)dspricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$()) q)`dspricing insert(123;2003.03.23;1.0;3.0;4.0;2.0;1000) q)`dspricing insert(123;2003.03.24;1.0;3.0;4.0;2.0;2000) q)save `:dspricing q)`:dspricing upsert(123;2003.03.25;1.0;3.0;4.0;2.0;1500)
now i'm trying in java , have following code
public class loadds { sqlsession session; private datastreammapper mapper ; public static void main(string args[]){ final qconnection q = new qbasicconnection(args.length >= 1 ? args[0] : "localhost", args.length >= 2 ? integer.parseint(args[1]) : 5001, "user", "pwd"); loadds l=new loadds(); l.session = mybatisconnectionfactory.getsqlsessionfactory("smalls").opensession(); l.mapper = l.session.getmapper(datastreammapper.class); list<datastream> prices = l.mapper.selecthistoricalprices(1); try { q.open(); q.sync("upsert", "'dspricing", l.getdata(prices)); } catch (qexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } // dspricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$()) private object[] getdata(list<datastream> prices) { final object[] data = new object[] {new int[prices.size()], new qdate[prices.size()], new float[prices.size()], new float[prices.size()], new float[prices.size()],new float[prices.size()], new int[prices.size()] }; ( int = 0; < prices.size(); i++ ) { ((int[]) data[0])[i] = prices.get(i).getinfocode(); ((qdate[]) data[1])[i] = new qdate(prices.get(i).getmarketdate()); ((float[]) data[2])[i] = (float)prices.get(i).getopen_(); ((float[]) data[3])[i] = (float)prices.get(i).getclose_(); ((float[]) data[4])[i] = (float)prices.get(i).gethigh(); ((float[]) data[5])[i] = (float)prices.get(i).getlow(); ((int[]) data[6])[i] = (int)prices.get(i).getvolume(); } return data; }
}
can tell me i'm doing wrong? data not getting saved , i've tried multiple variations. i'd prefer load data sql , save disk initial load.
you want replace "'dspricing" (note apostrohe) "dspricing" or perhaps ":dspricing". qjava converts strings symbols, "'dspricing" gets sent in q writing `$"'dspricing".
Comments
Post a Comment