# re: \[personal kdb+\] KDB+ & Java

**URL:** https://forum.kx.com/t/re-personal-kdb-kdb-java/8022
**Category:** Community Support
**Tags:** imported, kdb-and-q
**Created:** [December 7, 2012, 3:05pm UTC](https://forum.kx.com/t/re-personal-kdb-kdb-java/8022 "2012-12-07T15:05:00Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Ryan\_Hamilton](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@Ryan\_Hamilton](https://forum.kx.com/u/Ryan_Hamilton)
#### Post date: [December 7, 2012, 3:05pm UTC](https://forum.kx.com/t/re-personal-kdb-kdb-java/8022/1 "2012-12-07T15:05:00Z")

</div>

Hi Paolo,

The page on code kx documents the API thoroughly:  
[http://code.kx.com/wiki/Cookbook/InterfacingWithJava](http://code.kx.com/wiki/Cookbook/InterfacingWithJava)

Below is an example of constructing an object for upsert. The data I amsending is unkeyed, if you want to send keyed,the easiest way to see theformat is by querying a keyed table bringing the data into java andviewing it in the debugger.

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // create vectors for each column  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Time t = new Time[numRecords];  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String sym = new String[numRecords];  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double price = new double[numRecords];  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // loop through filling the columns with data  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for(int i=0; i\<trades.size(); i++) {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; t[i] = new Time(XXXX);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sym[i] = “dummySym”;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; price[i] = R.nextDouble() \* 100.0; // R = random  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // create the table itself from the separate columns  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Object data = new Object { t, sym, price, size, stop, cond, ex };  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; c.Flip tab = new c.Flip(new c.Dict(COL\_NAMES, data));

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // create the command to insert the table of data into the named table.  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Object updStatement = new Object { “upsert”, “tablename”, tab };  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; conn.ks(updStatement);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch (IOException e) {  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.err.println(“error sending feed to server.”);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }

Regards  
Ryan Hamilton

* * *

**From** : “paolo.trpnl” \<tarpanelli@libero.it\>  
**Sent** : Friday, December 07, 2012 1:00 PM  
**To** : [personal-kdbplus@googlegroups.com](mailto:personal-kdbplus@googlegroups.com)  
**Subject** : [personal kdb+] KDB+ & Java

Hello,  
I am trying to find some example about how use java to create insert/upsert keyedtable but I can not find something interesting

Is there any one who can help me

Thanks in advance  
Paolo

–  
Submitted via Google Groups
