<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: apache phoenix jdbctemplate PreparedStatement in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228641#M63952</link>
    <description>&lt;P&gt;Hi, Many Thanks.&lt;/P&gt;&lt;P&gt; May i also ask, Long[] is already an array object why do i still need to call createArrayOf function ?&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 16:40:49 GMT</pubDate>
    <dc:creator>yebinianhi</dc:creator>
    <dc:date>2017-06-30T16:40:49Z</dc:date>
    <item>
      <title>apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228636#M63947</link>
      <description>&lt;P&gt;Hi, I am using jdbctemplate connecting to an apache phoenix database, but i had a problem which the database has a record store an array(long[]). &lt;/P&gt;&lt;P&gt;In the database, the column is defined as "USER_ROUTES BIGINT[]  NULL",&lt;/P&gt;&lt;P&gt;In java, i use the long[] instead.&lt;/P&gt;&lt;P&gt;How to insert an array as a variable in the  PreparedStatement&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;BatchPreparedStatementSetter bpss = new BatchPreparedStatementSetter() {&lt;/P&gt;&lt;P&gt;    @Override &lt;/P&gt;&lt;P&gt;    public void setValues(PreparedStatement ps, int i) throws SQLException { &lt;/P&gt;&lt;P&gt;            EnviData ed=eds.get(i); &lt;/P&gt;&lt;P&gt;           ps.setString(1, ed.getPATIENT_ID()); &lt;/P&gt;&lt;P&gt;           ps.setInt(2, ed.getMOBILE_ID()); &lt;/P&gt;&lt;P&gt;          ps.setArray(3, ed.getUSER_ROUTES());  } &lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;The Function getUSER_ROUTES() will return an long[]. but, the program shows error.&lt;/P&gt;&lt;P&gt;How to solve it?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 00:25:32 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228636#M63947</guid>
      <dc:creator>yebinianhi</dc:creator>
      <dc:date>2017-06-30T00:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228637#M63948</link>
      <description>&lt;P&gt;Can you please share the error you are getting ?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 00:59:17 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228637#M63948</guid>
      <dc:creator>dineshc</dc:creator>
      <dc:date>2017-06-30T00:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228638#M63949</link>
      <description>&lt;P&gt;You need to create java.sql.Array by calling conn.createArrayOf with long array. For ex:&lt;/P&gt;&lt;PRE&gt;Long[] longArr =new Long[2];
longArr[0] = 25l;
longArr[1] = 36l;
array = conn.createArrayOf("BIGINT", longArr);
ps.setArray(3, array);
&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 01:02:23 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228638#M63949</guid>
      <dc:creator>rchintaguntla</dc:creator>
      <dc:date>2017-06-30T01:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228639#M63950</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18083/yebinianhi.html" nodeid="18083"&gt;@Bin Ye&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/18083/yebinianhi.html" nodeid="18083"&gt;&lt;/A&gt;Since ed.getUSER_ROUTES() is returning long[], you must first convert it to an array of Object using ArrayUtils from apache-commons-lang jar.&lt;/P&gt;&lt;P&gt;Add it using maven to your java project or import the jar.&lt;/P&gt;&lt;P&gt;Download jar from &lt;A href="http://www.java2s.com/Code/Jar/a/Downloadapachecommonslangjar.htm"&gt;here&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;long[] vals = {1234,9876,77878};  //example of user routes long [] being returned.
Long[] obj = ArrayUtils.toObject(vals); &lt;/PRE&gt;&lt;P&gt;Now use the connection object's createArrayOf() method as shown below:&lt;/P&gt;&lt;PRE&gt;Array arrayOfUserRoutes = connection.createArrayOf("long", obj);             

ps.setArray(3, arrayOfUserRoutes );&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 01:30:14 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228639#M63950</guid>
      <dc:creator>dineshc</dc:creator>
      <dc:date>2017-06-30T01:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228640#M63951</link>
      <description>&lt;P&gt;Many thanks, I just realised i need to convert long[] to Long[]&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 16:36:44 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228640#M63951</guid>
      <dc:creator>yebinianhi</dc:creator>
      <dc:date>2017-06-30T16:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228641#M63952</link>
      <description>&lt;P&gt;Hi, Many Thanks.&lt;/P&gt;&lt;P&gt; May i also ask, Long[] is already an array object why do i still need to call createArrayOf function ?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 16:40:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228641#M63952</guid>
      <dc:creator>yebinianhi</dc:creator>
      <dc:date>2017-06-30T16:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: apache phoenix jdbctemplate PreparedStatement</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228642#M63953</link>
      <description>&lt;P&gt;Yes, you will still need to call createArrayOf function. The ps.setArray expects a value of type java.sql.Array, which is different from Long[].
Please consider accepting the answer if this has helped.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 22:42:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/apache-phoenix-jdbctemplate-PreparedStatement/m-p/228642#M63953</guid>
      <dc:creator>dineshc</dc:creator>
      <dc:date>2017-06-30T22:42:08Z</dc:date>
    </item>
  </channel>
</rss>

