<?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>topic Re: Problem with converting DB table to RTDM TABLE with datetime column - Groovy in SAS Customer Intelligence</title>
    <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/599833#M1305</link>
    <description>&lt;P&gt;Yes,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;once you have an Calendar object instance, you use it as a 2nd argument of newRow.columnDataSet().&lt;/P&gt;
&lt;P&gt;Also note as 1st argument, you can use also the column name (String). e.g. newRow.columnDataSet("myDateTimeCol", myCalendarInstance);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;an example I used once, uses different method of new Datagrid row creation, however shows how to parse ResultSet into Datagrid for String, Long (RTDM Integer), Double and Calendar (RTDM Datetime). You can create new empty row and use columnDataSet as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (rs != null) {&lt;BR /&gt;List&amp;lt;Object&amp;gt; list = new ArrayList&amp;lt;Object&amp;gt;(); &lt;BR /&gt;while (rs.next()) {&lt;BR /&gt;//read values from ResultSet and add them into offerRepDatagrid&lt;BR /&gt;list.add(getLong(rs, "Col1"));&lt;BR /&gt;list.add(rs.getString("Col2"));&lt;BR /&gt;list.add(getDouble(rs, "Col3"));&lt;BR /&gt;list.add(getCalendar(rs, "Col4"));&lt;BR /&gt;offerRepDatagrid.rowAdd(list); &lt;BR /&gt;list.clear(); &lt;BR /&gt;rsCount++;&lt;BR /&gt;}&lt;BR /&gt;} &lt;BR /&gt;if (rs != null) rs.close();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;private Long getLong(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;long l = rs.getLong(colName);&lt;BR /&gt;return rs.wasNull() ? null : l;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;private Double getDouble(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;Double d = rs.getDouble(colName);&lt;BR /&gt;return rs.wasNull() ? null : d;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;private Calendar getCalendar(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;Calendar c = Calendar.getInstance(timeZone);&lt;BR /&gt;Date d = rs.getDate(colName);&lt;BR /&gt;if (rs.wasNull()) return null;&lt;BR /&gt;else {&lt;BR /&gt;c.setTime(d);&lt;BR /&gt;return c;&lt;BR /&gt;} &lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2019 15:08:54 GMT</pubDate>
    <dc:creator>peh</dc:creator>
    <dc:date>2019-10-28T15:08:54Z</dc:date>
    <item>
      <title>Problem with converting DB table to RTDM TABLE with datetime column - Groovy</title>
      <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/591156#M1280</link>
      <description>&lt;P&gt;Hi everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having problems get columns and data rows of datetime value from DB and make it a rtdm table (data grid),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;something is wrong in the get...() function syntex,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;trying to run the code:&lt;/P&gt;&lt;P&gt;import org.apache.log4j.Logger&lt;/P&gt;&lt;P&gt;import java.sql.Connection&lt;/P&gt;&lt;P&gt;import java.sql.PreparedStatement&lt;/P&gt;&lt;P&gt;import java.sql.ResultSet&lt;/P&gt;&lt;P&gt;import java.sql.SQLException&lt;/P&gt;&lt;P&gt;import org.apache.commons.logging.Log&lt;/P&gt;&lt;P&gt;import org.apache.commons.logging.LogFactory&lt;/P&gt;&lt;P&gt;import com.sas.analytics.ph.common.RTDMTable&lt;/P&gt;&lt;P&gt;import com.sas.analytics.ph.common.RTDMTable.Row&lt;/P&gt;&lt;P&gt;import com.sas.analytics.ph.common.exp.SymbolTable&lt;/P&gt;&lt;P&gt;import com.sas.analytics.ph.common.jaxb.DataTypes&lt;/P&gt;&lt;P&gt;import com.sas.rtdm.implementation.engine.EventInfo&lt;/P&gt;&lt;P&gt;import javax.sql.DataSource&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RTDMTable TABLE;&lt;/P&gt;&lt;P&gt;TABLE = new RTDMTable();&lt;/P&gt;&lt;P&gt;TABLE.columnAdd("stringcol", DataTypes.STRING, Collections.emptyList());&lt;/P&gt;&lt;P&gt;TABLE.columnAdd("floatcol", DataTypes.FLOAT, Collections.emptyList());&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TABLE.columnAdd("datecol", DataTypes.DATETIME, Collections.emptyList());&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*get rows and columns by query from DB&lt;/P&gt;&lt;P&gt;stmt = conn.prepareStatement(queryToSubmit)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Row newRow = TABLE.rowAdd()&lt;/P&gt;&lt;P&gt;newRow.columnDataSet("stringcol", rs.getString(1))&lt;/P&gt;&lt;P&gt;newRow.columnDataSet("floatcol", rs.getDouble(2))&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;newRow.columnDataSet("datecol", rs.getDateTime(3))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--------&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;Caused by: groovy.lang.MissingMethodException: No signature of method: org.apache.commons.dbcp.DelegatingResultSet.getDateTime() is applicable for argument types: (java.lang.Integer) values: [3]&lt;/P&gt;&lt;P&gt;Possible solutions: getDate(int), getTime(int), updateTime(int, java.sql.Time), getDate(java.lang.String), getDate(int, java.util.Calendar), getTime(java.lang.String)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;HELP &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ?&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Sep 2019 12:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/591156#M1280</guid>
      <dc:creator>RTDM_User</dc:creator>
      <dc:date>2019-09-24T12:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with converting DB table to RTDM TABLE with datetime column - Groovy</title>
      <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/592124#M1290</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;RTDM datatype DateTime is represented as Calendar in Java/Groovy.&lt;/P&gt;&lt;P&gt;Here is a piece of code that can be used to retrieve Calendar from ResultSet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import java.sql.SQLException;&lt;/P&gt;&lt;P&gt;import java.sql.ResultSet;&lt;/P&gt;&lt;P&gt;import java.util.Calendar;&lt;/P&gt;&lt;P&gt;import java.sql.Date;&lt;/P&gt;&lt;P&gt;import java.util.TimeZone;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;private Calendar getCalendar(ResultSet rs, String colName) throws SQLException {&lt;/P&gt;&lt;P&gt;Calendar c = Calendar.getInstance(timeZone);&lt;/P&gt;&lt;P&gt;Date d = rs.getDate(colName);&lt;/P&gt;&lt;P&gt;if (rs.wasNull()) return null;&lt;/P&gt;&lt;P&gt;else {&lt;/P&gt;&lt;P&gt;c.setTime(d);&lt;/P&gt;&lt;P&gt;return c;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to provide a TimeZone to create Calendar.&lt;/P&gt;&lt;P&gt;If you want to use client timezone, you can use the following code to retrieve client timezone as string.&lt;/P&gt;&lt;P&gt;import com.sas.rtdm.implementation.engine.EventInfo;&lt;/P&gt;&lt;P&gt;String timezoneId = evtInfo.getClientTimeZoneId();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2019 11:04:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/592124#M1290</guid>
      <dc:creator>peh</dc:creator>
      <dc:date>2019-09-27T11:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with converting DB table to RTDM TABLE with datetime column - Groovy</title>
      <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/592473#M1291</link>
      <description>&lt;P&gt;in addition to defining the calendar object you also need to use&amp;nbsp;&lt;CODE&gt;&lt;SPAN class="n"&gt;rs&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="na"&gt;getTimestamp.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="na"&gt;Cheers&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE&gt;&lt;SPAN class="na"&gt;James&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Sep 2019 11:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/592473#M1291</guid>
      <dc:creator>JamesAnderson</dc:creator>
      <dc:date>2019-09-29T11:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with converting DB table to RTDM TABLE with datetime column - Groovy</title>
      <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/599787#M1303</link>
      <description>&lt;P&gt;Thank you very much for the response,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where should i put it in my code?&lt;/P&gt;&lt;P&gt;how do i insert this "converted" column to an RTDM Table as described above?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"newRow.columnDataSet(..." ?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;OR&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp; &amp;nbsp; other way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;its a multiple row table with 20 columns.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 13:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/599787#M1303</guid>
      <dc:creator>RTDM_User</dc:creator>
      <dc:date>2019-10-28T13:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with converting DB table to RTDM TABLE with datetime column - Groovy</title>
      <link>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/599833#M1305</link>
      <description>&lt;P&gt;Yes,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;once you have an Calendar object instance, you use it as a 2nd argument of newRow.columnDataSet().&lt;/P&gt;
&lt;P&gt;Also note as 1st argument, you can use also the column name (String). e.g. newRow.columnDataSet("myDateTimeCol", myCalendarInstance);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;an example I used once, uses different method of new Datagrid row creation, however shows how to parse ResultSet into Datagrid for String, Long (RTDM Integer), Double and Calendar (RTDM Datetime). You can create new empty row and use columnDataSet as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (rs != null) {&lt;BR /&gt;List&amp;lt;Object&amp;gt; list = new ArrayList&amp;lt;Object&amp;gt;(); &lt;BR /&gt;while (rs.next()) {&lt;BR /&gt;//read values from ResultSet and add them into offerRepDatagrid&lt;BR /&gt;list.add(getLong(rs, "Col1"));&lt;BR /&gt;list.add(rs.getString("Col2"));&lt;BR /&gt;list.add(getDouble(rs, "Col3"));&lt;BR /&gt;list.add(getCalendar(rs, "Col4"));&lt;BR /&gt;offerRepDatagrid.rowAdd(list); &lt;BR /&gt;list.clear(); &lt;BR /&gt;rsCount++;&lt;BR /&gt;}&lt;BR /&gt;} &lt;BR /&gt;if (rs != null) rs.close();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;private Long getLong(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;long l = rs.getLong(colName);&lt;BR /&gt;return rs.wasNull() ? null : l;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;private Double getDouble(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;Double d = rs.getDouble(colName);&lt;BR /&gt;return rs.wasNull() ? null : d;&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;private Calendar getCalendar(ResultSet rs, String colName) throws SQLException {&lt;BR /&gt;Calendar c = Calendar.getInstance(timeZone);&lt;BR /&gt;Date d = rs.getDate(colName);&lt;BR /&gt;if (rs.wasNull()) return null;&lt;BR /&gt;else {&lt;BR /&gt;c.setTime(d);&lt;BR /&gt;return c;&lt;BR /&gt;} &lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2019 15:08:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Customer-Intelligence/Problem-with-converting-DB-table-to-RTDM-TABLE-with-datetime/m-p/599833#M1305</guid>
      <dc:creator>peh</dc:creator>
      <dc:date>2019-10-28T15:08:54Z</dc:date>
    </item>
  </channel>
</rss>

