<?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: jdbc errors when parameter is a boolean in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78939#M7735</link>
    <description>&lt;P&gt;Thank you very much for your answer and suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data type is Boolean - unless I'm mistaken, it is supported because I did the 2 following experiments:&lt;/P&gt;&lt;P&gt;1. Used queryForList with an extra argument, manually specifying type of arguments, where argTypes uses&amp;nbsp;&lt;SPAN&gt;java.sql&lt;/SPAN&gt;.Types.&lt;SPAN&gt;BOOLEAN (num value == 16)&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;jdbcTemplate&lt;/SPAN&gt;.queryForList(sql, args.toArray(), argTypes); &lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;2. Using a prepared statement&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;ResultSet resultSet = &lt;SPAN&gt;null&lt;/SPAN&gt;;&lt;BR /&gt;&lt;SPAN&gt;try &lt;/SPAN&gt;(PreparedStatement preparedStatement = &lt;SPAN&gt;dataSource&lt;/SPAN&gt;.getConnection().prepareStatement(sql)) {&lt;BR /&gt;    preparedStatement.setBoolean(&lt;SPAN&gt;1&lt;/SPAN&gt;, (Boolean) args.get(&lt;SPAN&gt;0&lt;/SPAN&gt;));&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Both work fine. I did a bit of deep debugging into JdbcTemplate source code and it seems like when using only queryForList(sql, args), the argument types in case of boolean don't get converted correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;While we should have&amp;nbsp;&lt;SPAN&gt;java.sql&lt;/SPAN&gt;.Types.&lt;SPAN&gt;BOOLEAN (int value 16), we get&amp;nbsp;java.sql.Types.BIT (int value -7)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Jul 2024 09:32:56 GMT</pubDate>
    <dc:creator>JVesely</dc:creator>
    <dc:date>2024-07-16T09:32:56Z</dc:date>
    <item>
      <title>jdbc errors when parameter is a boolean</title>
      <link>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78545#M7733</link>
      <description>&lt;P&gt;I'm trying to query a table from Java code. The query works when I use a databricks notebook / query editor directly in Databricks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when using Jdbc with Spring, I get following stacktrace.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT rowkey, sendReminder FROM ANIMAL WHERE sendReminder = ?]; SQL state [HY000]; error code [500352]; [Databricks][JDBCDriver](500352) Error getting the parameter data type: HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE; nested exception is java.sql.SQLException: [Databricks][JDBCDriver](500352) Error getting the parameter data type: HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1542)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:667)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:744)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:757)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:810)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I tried to search for&amp;nbsp;HY000,&amp;nbsp;500352 and&amp;nbsp;HIVE_PARAMETER_QUERY_DATA_TYPE_ERR_NON_SUPPORT_DATA_TYPE but didn't get any results that seemed helpful.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Using other datatypes as parameter than boolean works.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Did you face this issue, is it a known thing and most importantly, is there a workaround?&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2024 14:28:43 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78545#M7733</guid>
      <dc:creator>JVesely</dc:creator>
      <dc:date>2024-07-12T14:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: jdbc errors when parameter is a boolean</title>
      <link>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78939#M7735</link>
      <description>&lt;P&gt;Thank you very much for your answer and suggestions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data type is Boolean - unless I'm mistaken, it is supported because I did the 2 following experiments:&lt;/P&gt;&lt;P&gt;1. Used queryForList with an extra argument, manually specifying type of arguments, where argTypes uses&amp;nbsp;&lt;SPAN&gt;java.sql&lt;/SPAN&gt;.Types.&lt;SPAN&gt;BOOLEAN (num value == 16)&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;jdbcTemplate&lt;/SPAN&gt;.queryForList(sql, args.toArray(), argTypes); &lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;2. Using a prepared statement&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;ResultSet resultSet = &lt;SPAN&gt;null&lt;/SPAN&gt;;&lt;BR /&gt;&lt;SPAN&gt;try &lt;/SPAN&gt;(PreparedStatement preparedStatement = &lt;SPAN&gt;dataSource&lt;/SPAN&gt;.getConnection().prepareStatement(sql)) {&lt;BR /&gt;    preparedStatement.setBoolean(&lt;SPAN&gt;1&lt;/SPAN&gt;, (Boolean) args.get(&lt;SPAN&gt;0&lt;/SPAN&gt;));&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Both work fine. I did a bit of deep debugging into JdbcTemplate source code and it seems like when using only queryForList(sql, args), the argument types in case of boolean don't get converted correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;While we should have&amp;nbsp;&lt;SPAN&gt;java.sql&lt;/SPAN&gt;.Types.&lt;SPAN&gt;BOOLEAN (int value 16), we get&amp;nbsp;java.sql.Types.BIT (int value -7)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 09:32:56 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78939#M7735</guid>
      <dc:creator>JVesely</dc:creator>
      <dc:date>2024-07-16T09:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: jdbc errors when parameter is a boolean</title>
      <link>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78982#M7736</link>
      <description>&lt;P&gt;As I see it, there's two things:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;jdbcTemplate converts boolean to bit. This is according to JDBC specs (this is a "spring-jdbc" thing and according to documentation; the jdbcTemplate.queryForList makes the best possible guess of the desired type).&lt;/LI&gt;&lt;LI&gt;Databricks can't handle a boolean marked as bit&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Either using PreparedStatement or queryForList(sql, args, argTypes) works.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 13:28:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/jdbc-errors-when-parameter-is-a-boolean/m-p/78982#M7736</guid>
      <dc:creator>JVesely</dc:creator>
      <dc:date>2024-07-16T13:28:14Z</dc:date>
    </item>
  </channel>
</rss>

