<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Anatoly</title>
    <description>The latest articles on DEV Community by Anatoly (@buckelieg).</description>
    <link>https://dev.to/buckelieg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F355838%2F35266c8d-b43d-4e3d-ab69-579c9dd9afbb.png</url>
      <title>DEV Community: Anatoly</title>
      <link>https://dev.to/buckelieg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/buckelieg"/>
    <language>en</language>
    <item>
      <title>JDBC and Streams have never been simpler</title>
      <dc:creator>Anatoly</dc:creator>
      <pubDate>Thu, 04 Jul 2024 17:51:24 +0000</pubDate>
      <link>https://dev.to/buckelieg/jdbc-and-streams-have-never-been-easier-58f2</link>
      <guid>https://dev.to/buckelieg/jdbc-and-streams-have-never-been-easier-58f2</guid>
      <description>&lt;h3&gt;
  
  
  Just updated a library which makes life much easier when speaking about databases...
&lt;/h3&gt;

&lt;p&gt;When streams were introduced in java I got myself thinking of how I can leverage it with databases. It is "pretty common" task to write SQL queries and process the results within Java. And the more I was ought to deal with prepared statements, result sets, all those &lt;code&gt;SQLException&lt;/code&gt;s etc., the more I was disappointed. Searching the WEB for solutions where I wanted to find two worlds collided conveniently - I found no suitable one! Of course there are many libraries that afford some, but neither of them suited me. I wanted something else. Therefore I decided to write one myself for myself.&lt;/p&gt;

&lt;h4&gt;
  
  
  My goals...
&lt;/h4&gt;

&lt;p&gt;...were based on my background experience:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No prepared boilerplate and &lt;code&gt;SQLException&lt;/code&gt;s&lt;/li&gt;
&lt;li&gt;Executing arbitrary scripts&lt;/li&gt;
&lt;li&gt;Minimal configuration&lt;/li&gt;
&lt;li&gt;"Real" streams (lazily data fetching)&lt;/li&gt;
&lt;li&gt;Raw SQL&lt;/li&gt;
&lt;li&gt;Database is just a method invocation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;and some others - don't remember them all :)&lt;/p&gt;

&lt;p&gt;So after some time I ended up with this:&lt;/p&gt;

&lt;h3&gt;
  
  
  A brief
&lt;/h3&gt;

&lt;p&gt;1 - Get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
  &amp;lt;groupId&amp;gt;com.github.buckelieg&amp;lt;/groupId&amp;gt;
  &amp;lt;artifactId&amp;gt;jdbc-fn&amp;lt;/artifactId&amp;gt;
  &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2 - Setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DB db = DB.builder()
        .withMaxConnections(10)
        .build(() -&amp;gt; DriverManager.getConnection("vendor-specific-string"));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3 - Use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Collection&amp;lt;String&amp;gt; names = db.select("SELECT name FROM users WHERE ID IN (?, ?)", 1, 2).execute(rs -&amp;gt; rs.getString("name")).collect(Collectors.toList());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy to share: &lt;a href="https://buckelieg.github.io/jdbc-fn/" rel="noopener noreferrer"&gt;jdbc-fn&lt;/a&gt; project.&lt;/p&gt;

</description>
      <category>jdbc</category>
      <category>lambda</category>
      <category>java</category>
      <category>functional</category>
    </item>
  </channel>
</rss>
