# Kdb+ and MATLAB interaction: WRITE works well, READ problematic

**URL:** <https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [February 6, 2015, 4:15pm UTC](https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459 "2015-02-06T16:15:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_L\_V](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@A\_L\_V](https://forum.kx.com/u/A_L_V)\
**Post date:** [February 6, 2015, 4:15pm UTC](https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459/1 "2015-02-06T16:15:00Z")

</div>

Added **kx.jar** to **javaclasspath** (as recommended here).  
**javaaddpath(‘/home/ALV/Downloads/kx.jar’);**

Java connected to the database and managed to write fine.

**q=kx(‘localhost’,5000);  
exec(q,‘n:1000000;’);  
exec(q,‘item:`apple`banana`orange`pear;’);  
exec(q,‘city:`beijing`chicago`london`paris;’);  
exec(q,‘tab:([]time:asc n?0D0;n?item;amount:n?100;n?city);’);**

Now wanted to read back the data (run a query).

**d = fetch(q,‘select from tab where item=`banana’);**

Got an error back:  
Error using kx/fetch (line 64)  
Java exception occurred:  
c$KException: type  
&nbsp;&nbsp;&nbsp; at c.k(c.java:581)  
&nbsp;&nbsp;&nbsp; at c.k(c.java:590)  
&nbsp;&nbsp;&nbsp; at c.k(c.java:593)

Tried to fix it by compiling jdbc.class to jdbc.jar and addind to the javaclasspath, but that did not help.  
**javaaddpath(‘/home/ALV/Downloads/jdbc.jar’);**

How can I run a query from MATLAB without getting the error?

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [February 6, 2015, 4:20pm UTC](https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459/2 "2015-02-06T16:20:00Z")

</div>

as a tip, when faced with these problems, remove each column from the result set to try to identify the problem column. e.g.

d = fetch(q,‘select item,amount,city from tab where item=`banana’);

also include the version/release of matlab and kdb+ which you are using. If you happen to identify that the time column is the problem, try changing its type, e.g.

d = fetch(q,‘select time:`time$time,item,amount,city from tab where item=`banana’);

---

<div class="post-metadata">

**Author:** ![A\_L\_V](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@A\_L\_V](https://forum.kx.com/u/A_L_V)\
**Post date:** [February 6, 2015, 5:25pm UTC](https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459/3 "2015-02-06T17:25:00Z")

</div>

Hi Charles. Tried your syntax recommendation. Not the output I expected:

\*\*\>\> d = fetch(q,‘select time:`time$time,item,amount,city from tab where item=`banana’);  
\>\> d

d =

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; time: [249636x1 double]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item: {249636x1 cell}  
&nbsp;&nbsp;&nbsp; amount: [249636x1 int64]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; city: {249636x1 cell}\*\*

The version issue does not seem good (too much of a specific detail); R2014a, not sure about the Kdb+ version but the latest 32bit from online.

---

<div class="post-metadata">

**Author:** ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)\
**Post date:** [February 6, 2015, 6:16pm UTC](https://forum.kx.com/t/kdb-and-matlab-interaction-write-works-well-read-problematic/9459/4 "2015-02-06T18:16:00Z")

</div>

Looks ok to me. Time coming through as a double probably means as a fraction of the day.  
See this page for some guidance

http://code.kx.com/wiki/Cookbook/IntegratingWithMatlab

btw, for future reference

The kdb+ version is printed on startup in the startup banner. The important details are the version and release date, e.g.&nbsp;KDB+ 3.3t 2015.02.06
