<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by priya raj on Medium]]></title>
        <description><![CDATA[Stories by priya raj on Medium]]></description>
        <link>https://medium.com/@priyarajtt?source=rss-5563f4a98b2d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HVxrJXZISW9d4c4hTaoqXA.jpeg</url>
            <title>Stories by priya raj on Medium</title>
            <link>https://medium.com/@priyarajtt?source=rss-5563f4a98b2d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 19:35:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priyarajtt/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Database Triggers Across RDBMS and NoSQL: A Comprehensive Comparison]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://priyarajtt.medium.com/database-triggers-across-rdbms-and-nosql-a-comprehensive-comparison-2893532724e7?source=rss-5563f4a98b2d------2"><img src="https://cdn-images-1.medium.com/max/600/1*lR3EZmIQT4Hep4G3e5Pdgw.png" width="600"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://priyarajtt.medium.com/database-triggers-across-rdbms-and-nosql-a-comprehensive-comparison-2893532724e7?source=rss-5563f4a98b2d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://priyarajtt.medium.com/database-triggers-across-rdbms-and-nosql-a-comprehensive-comparison-2893532724e7?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2893532724e7</guid>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Wed, 10 Jun 2026 06:41:45 GMT</pubDate>
            <atom:updated>2026-06-10T06:41:45.741Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[What are the disadvantages of using an asterisk (*) in SQL “select” queries?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://priyarajtt.medium.com/what-are-the-disadvantages-of-using-an-asterisk-in-sql-select-queries-5a111d4d64cf?source=rss-5563f4a98b2d------2"><img src="https://cdn-images-1.medium.com/max/600/1*uNPnIPi0UFo_-1UccglhBg.png" width="600"></a></p><p class="medium-feed-snippet">Using the asterisk (*) in SQL SELECT queries is convenient but has several important disadvantages:</p><p class="medium-feed-link"><a href="https://priyarajtt.medium.com/what-are-the-disadvantages-of-using-an-asterisk-in-sql-select-queries-5a111d4d64cf?source=rss-5563f4a98b2d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://priyarajtt.medium.com/what-are-the-disadvantages-of-using-an-asterisk-in-sql-select-queries-5a111d4d64cf?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a111d4d64cf</guid>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 10:58:18 GMT</pubDate>
            <atom:updated>2026-06-08T10:58:18.132Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[How do you list all fields from one table in MySQL?]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://priyarajtt.medium.com/how-do-you-list-all-fields-from-one-table-in-mysql-d1f2a1aaecbe?source=rss-5563f4a98b2d------2"><img src="https://cdn-images-1.medium.com/max/600/1*luWHswULaQTNT_RREhoeJw.png" width="600"></a></p><p class="medium-feed-snippet">There are 4 different options are possible</p><p class="medium-feed-link"><a href="https://priyarajtt.medium.com/how-do-you-list-all-fields-from-one-table-in-mysql-d1f2a1aaecbe?source=rss-5563f4a98b2d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://priyarajtt.medium.com/how-do-you-list-all-fields-from-one-table-in-mysql-d1f2a1aaecbe?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1f2a1aaecbe</guid>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Mon, 08 Jun 2026 10:04:42 GMT</pubDate>
            <atom:updated>2026-06-08T10:04:42.018Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Cybersecurity Daily Links — 03–06–2026]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://priyarajtt.medium.com/cybersecurity-daily-links-03-06-2026-93122b604f60?source=rss-5563f4a98b2d------2"><img src="https://cdn-images-1.medium.com/max/1200/1*XnjDeS35pD06o4RYqyPXeA.png" width="1200"></a></p><p class="medium-feed-snippet">Recent threats &#x2014; from WeedHack targeting Minecraft players and CountLoader&#x2019;s surge to 86K infections, to miner distribution via pirated&#x2026;</p><p class="medium-feed-link"><a href="https://priyarajtt.medium.com/cybersecurity-daily-links-03-06-2026-93122b604f60?source=rss-5563f4a98b2d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://priyarajtt.medium.com/cybersecurity-daily-links-03-06-2026-93122b604f60?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/93122b604f60</guid>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 08:41:21 GMT</pubDate>
            <atom:updated>2026-06-03T08:41:21.038Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[AI Daily Links — 03–06 -2026]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://priyarajtt.medium.com/ai-daily-links-03-06-2026-7afdf79477d7?source=rss-5563f4a98b2d------2"><img src="https://cdn-images-1.medium.com/max/1200/1*vZyk3jefwA5y7hO8_jI76Q.png" width="1200"></a></p><p class="medium-feed-snippet">Microsoft&#x2019;s renewed push in quantum computing, Google&#x2019;s new search controls for site owners, and practical consumer savings from June&#x2026;</p><p class="medium-feed-link"><a href="https://priyarajtt.medium.com/ai-daily-links-03-06-2026-7afdf79477d7?source=rss-5563f4a98b2d------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://priyarajtt.medium.com/ai-daily-links-03-06-2026-7afdf79477d7?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7afdf79477d7</guid>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Wed, 03 Jun 2026 08:36:59 GMT</pubDate>
            <atom:updated>2026-06-03T08:36:59.299Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[AngularJS | SQL]]></title>
            <link>https://priyarajtt.medium.com/angularjs-sql-9c644658986d?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c644658986d</guid>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 07:08:50 GMT</pubDate>
            <atom:updated>2022-09-20T07:08:50.649Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction on AngularJS</strong> <br>AngularJS is a JavaScript MVC or Model-View-Controller framework developed by Google. It helps developers to build well structured, easily testable, and maintainable front-end applications. <br><strong>Features</strong> <br>Important concepts in Angular JS Library is given below :</p><p>html</p><pre>&lt;table&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Concept&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Template&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Directives&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Model&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Scope&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Expressions&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Compiler&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Filter&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Data Binding&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Controller&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Module&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;&lt;Strong&gt;Service&lt;/Strong&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;/table&gt;</pre><p><strong>Need of AngularJS Framework explanation with a basic example</strong> <br>With the directives to the HTML elements and attributes, dynamic web pages are easily created by adding additional coding. <br>AngularJS is pretty much helpful for displaying data from a Database. Provided data should be in a JSON format. Let’s see an example of it. Data is in MySQL and on server side PHP interacts with MySQL and gets the data in JSON format. Angular JS displays the output. <br>With the basic example below, let us see in detail about Angular JS SQL.<br>//Angular JS</p><p>javascript</p><pre>&lt;html &gt;<br>&lt;style&gt;<br>table, th , td  {<br>  border: 1px solid grey;<br>  border-collapse: collapse;<br>  padding: 5px;<br>}<br>table tr:nth-child(odd) {<br>  background-color: #f1f1f1;<br>}<br>table tr:nth-child(even) {<br>  background-color: #ffffff;<br>}<br>&lt;/style&gt;<br>&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js&quot;&gt;&lt;/script&gt;<br>&lt;body&gt;</pre><pre>&lt;div ng-app=&quot;empApp&quot; ng-controller=&quot;employeeCtrl&quot;&gt;</pre><pre>&lt;table&gt;<br>  &lt;tr ng-repeat=&quot;output in names&quot;&gt;<br>    &lt;td&gt;{{ output.Name }}&lt;/td&gt;<br>    &lt;td&gt;{{ output.Country }}&lt;/td&gt;<br>  &lt;/tr&gt;<br>&lt;/table&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;script&gt;<br>var app = angular.module(&#39;empApp&#39;, []);<br>app.controller(&#39;employeeCtrl&#39;, function($scope, $http) {<br>  $http.get(&quot;employee_mysql.php&quot;)<br>  .then(function (response) {$scope.names = response.data.records;});<br>});<br>&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Explanation : <br>The ng-app directive is a starting point. Here “empApp” is given in ng-app, here initialization is started and compiles the HTML template <br>ng-controller is used to specify a controller in the HTML element. This controller will add behavior or maintain the data in that HTML element and its child elements <br><strong>Server Code PHP and MySQL</strong> <br><strong>Main thing here is the output should be in the format of JSON</strong></p><p>php</p><pre>&lt;?php<br>header(&quot;Access-Control-Allow-Origin: *&quot;);<br>header(&quot;Content-Type: application/json; charset=UTF-8&quot;);</pre><pre>$connection = new mysqli(&quot;myServer&quot;, &quot;&lt;username&gt;&quot;, &quot;&lt;password&gt;&quot;, &quot;&lt;dbname&gt;&quot;);</pre><pre>$result = $connection-&gt;query(&quot;SELECT EmployeeName, EmployeeCity, EmployeeCountry FROM Employees&quot;);</pre><pre>$output = &quot;&quot;;<br>while($rs = $result-&gt;fetch_array(MYSQLI_ASSOC)) {<br>  if ($output != &quot;&quot;) {$output = &quot;,&quot;;}<br>  $output.= &#39;{&quot;Name&quot;:&quot;&#39;  . $rs[&quot;EmployeeName&quot;] . &#39;&quot;,&#39;;<br>  $output.= &#39;&quot;City&quot;:&quot;&#39;   . $rs[&quot;EmployeeCity&quot;]        . &#39;&quot;,&#39;;<br>  $output.= &#39;&quot;Country&quot;:&quot;&#39;. $rs[&quot;EmployeeCountry&quot;]     . &#39;&quot;}&#39;;<br>}<br>$output=&#39;{&quot;records&quot;:[&#39;.$output.&#39;]}&#39;;<br>$connection-&gt;close();</pre><pre>echo($output);<br>?&gt;<br></pre><pre>Assume that Employees table is having 6 records and they are in MySQL. PHP code retrieve the data from MySQL in the format of JSON and angular JS displays the output <br><strong>OUTPUT:</strong><br>As Angular JS repeatedly loops and printing Name and Country, we will be getting the output (sample) in the below given fashion.</pre><p>&lt;!DOCTYPE html&gt;<br>&lt;html &gt;<br>&lt;style&gt;<br>table, th , td {<br> border: 1px solid grey;<br> border-collapse: collapse;<br> padding: 5px;<br>}<br>table tr:nth-child(odd) {<br> background-color: #f1f1f1;<br>}<br>table tr:nth-child(even) {<br> background-color: #ffffff;<br>}<br>&lt;/style&gt;<br>&lt;table&gt;<br>&lt;tr&gt;&lt;td&gt;Avinash&lt;/td&gt;&lt;td&gt;USA&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;Aisha&lt;/td&gt;&lt;td&gt;UK&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;Emma&lt;/td&gt;&lt;td&gt;Australia&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;Shreyas&lt;/td&gt;&lt;td&gt;India&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;Rachel&lt;/td&gt;&lt;td&gt;USA&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td&gt;Shravan&lt;/td&gt;&lt;td&gt;India&lt;/td&gt;&lt;/tr&gt;<br>&lt;/table&gt;</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c644658986d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Difference Between java.sql.Time, java.sql.Timestamp and java.sql.Date]]></title>
            <link>https://priyarajtt.medium.com/difference-between-java-sql-time-java-sql-timestamp-and-java-sql-date-a4879f2b816?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4879f2b816</guid>
            <category><![CDATA[java-sql]]></category>
            <category><![CDATA[java-timestamp]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-date-time]]></category>
            <category><![CDATA[java-date]]></category>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 06:51:12 GMT</pubDate>
            <atom:updated>2022-09-20T06:51:12.916Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction :</strong></p><p>Across the software projects, we are using java.sql.Time, java.sql.Timestamp and java.sql.Date in many instances. Whenever the java application interacts with the database, we should use these instead of java.util.Date. The reason is JDBC i.e. java database connectivity uses these to identify SQL Date and Timestamp.</p><p>Here let us see the differences between all the three and also their usages with few examples</p><p><strong>java.sql.Time java.sql.Timestamp java.sql.Date</strong></p><p>Stores hours, minutes. seconds and milliseconds alone.</p><p>Not stores date components and hence apt representation for SQL Time</p><p>Stores both Date and Time components</p><p>Stores years, months and days alone.</p><p>Not stores time components and hence apt representation for SQL Date</p><p>This is dependent and extend java.util.DateThis is dependent and extend java.util.DateThis is independent and does not extend java.util.DateAs not having Date information, Date information is normalized and can be set to 0 to confirm ANSI SQL DATEAs having both Date and Time , explicitly they are givenAs not having Time information, Time information is normalized and can be set to 0 to confirm ANSI SQL TimeNeed to have 2 columns one for java.sql.Date and java.sql.Time explicitly.In comparison with java.util.Date, as it is not storing nanosecond details though Date and Time info present, equals method between java.sql.Timestamp and java.util.Date return false only. Only one column enough to have both Date and Time.Nanosecond difference is much helpful in many scenariosNeed to have 2 columns one for java.sql.Date and java.sql.Time explicitly. From Java, setTimestamp() method is used to set the timestampFrom Java, setDate() method is used to set the date</p><p><strong>If we use timestamp as datatype, using DATE() function, we can extract date alone and using TIME() function, we can extract time alone. This is the biggest advantage. In Java, we can write below queries and get Date and Time part respectively as follows :</strong></p><p>— To get Date</p><p>select DATE(&lt;columnname&gt;) from &lt;tablename&gt;</p><p>— To get Time</p><p>select TIME(&lt;columnname&gt;) from &lt;tablename&gt;</p><p>Just to know about the time value of the occurrence of the action. i.e. whether student available on that time on any day etc.,For logging entries, to know about the absolute value of transactional timings, we can use timestampJust to know about the date value of the occurrence of the action. i.e. whether student available on that day</p><p>One can think that as java.sql.Timestamp can satisfy the requirement to store both Date and Time, then what is the need to have java.sql.Date and java.sql.Time. Let us see them in detail regarding the scenarios</p><p>Example 1 :</p><p>In schools, colleges, work places where ever to find out whether the student/employee is available on the specific day or not, it is enough to keep the java.sql.Date alone</p><p>Eg : EmployeeXXX available on certain date or not (or)</p><p>StudentXXX present to the school etc.,</p><p>So , generally we may be having a table like (let us check in MySQL)</p><p>//Here empOrStuInformation is the name of the table</p><p>create table empOrStuInformation</p><p>(</p><p>id int NOT NULL AUTO_INCREMENT PRIMARY KEY,</p><p>empOrStuName varchar(20),</p><p><strong>empOrStuAvailability DATE</strong></p><p>);</p><p>insert queries :</p><p>insert into empOrStuInformation(empOrStuName,empOrStuAvailability) values(‘xxx’,now());</p><p>insert into empOrStuInformation(empOrStuName,empOrStuAvailability) values(‘yyy’,now());</p><p>insert into empOrStuInformation(empOrStuName,empOrStuAvailability) values(‘zzz’,now());</p><p><strong>now() returns the current date and time in the configured time zone as a string but since we have DATE as datatype, we are getting date alone as the inserted value.</strong></p><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*6s_zZz_4aBswemG3.png" /></figure><p>Java</p><pre>import java.sql.Date;<br>String empOrStuAvailableDate = &quot;2021-01-01&quot;;<br>Date utilAvailabilityDate = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;).parse(empOrStuAvailableDate);<br>//jdbc connectivity expects java.sql.Date<br>java.sql.Date sqlAvailabilityDate = new java.sql.Date(utilAvailabilityDate.getTime()); </pre><pre>try{  <br>Class.forName(&quot;com.mysql.jdbc.Driver&quot;);  <br>//Here test is the databasename<br>//username is root and password is root<br>Connection con=DriverManager.getConnection(  <br>&quot;jdbc:mysql://localhost:3306/test&quot;,&quot;root&quot;,&quot;root&quot;);  <br> <br>PreparedStatement pStmt=con.prepareStatement(&quot;insert into empOrStuInformation (empOrStuName,empOrStuAvailability) values(?,?)&quot;);<br>//As we are using Date datatype, we are using setDate only...  <br>pStmt.setString(1,&quot;AAAA&quot;);<br>//The setDate() method is used to set date while setTimestamp() is used to set time.<br>pStmt.setDate(2,sqlAvailabilityDate);<br>pStmt.executeUpdate();<br>pStmt.close();<br>con.close(); <br>}catch(Exception ex){ <br>  System.out.println(ex);<br>}  <br>}  <br>}</pre><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*iB7Sg0qR6JYtFaTL.png" /></figure><p><strong>java.sql.Timestamp</strong></p><p>java.sql.Timestamp column is much helpful for logging the entries. Eg : By what time the student /employee reached the premises and left the premises, by what time the record is handed over, by what time the work is done etc.,</p><p>In Mysql, in below way we can create the table for the column containing timestamp</p><p>create table empOrStuInformation1</p><p>(</p><p>id int NOT NULL AUTO_INCREMENT PRIMARY KEY,</p><p>empOrStuName varchar(20),</p><p>empOrStuAvailability DATE,</p><p><strong>empOrStuLogEntry timestamp</strong></p><p>);</p><p>Java way of inserting records for timestamp</p><p>Java</p><pre>import java.sql.Date;<br>import java.sql.Timestamp;<br>String empOrStuAvailableDate = &quot;2021-01-01&quot;;<br>Date utilAvailabilityDate = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;).parse(empOrStuAvailableDate);<br>//jdbc connectivity expects java.sql.Date<br>java.sql.Date sqlAvailabilityDate = new java.sql.Date(utilAvailabilityDate.getTime()); </pre><pre>//create a java timestamp object that represents the current time <br>// (i.e., a &quot;current timestamp&quot;)<br>Calendar calendarInstance = Calendar.getInstance();<br>java.sql.Timestamp sampleJavaTimestampObject = <br>  new java.sql.Timestamp(calendarInstance.getTime().getTime());<br>try{  <br>Class.forName(&quot;com.mysql.jdbc.Driver&quot;);  <br>//Here test is the databasename<br>//username is root and password is root<br>Connection con=DriverManager.getConnection(  <br>&quot;jdbc:mysql://localhost:3306/test&quot;,&quot;root&quot;,&quot;root&quot;);  <br> <br>PreparedStatement pStmt=con.prepareStatement(&quot;insert into empOrStuInformation1 (empOrStuName,empOrStuAvailability,empOrStuLogEntry) values(?,?,?)&quot;);<br>//As we are using Date datatype, we are using setDate only...  <br>pStmt.setString(1,&quot;AAAA&quot;);<br>//The setDate() method is used to set date <br>pStmt.setDate(2,sqlAvailabilityDate);<br>//setTimestamp() is used to set time.<br>pStmt.setTimestamp(3, sampleJavaTimestampObject);<br>pStmt.executeUpdate();<br>pStmt.close();<br>con.close(); <br>}catch(Exception ex){ <br>  System.out.println(ex);<br>}  <br>}  <br>}</pre><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*X3iCm53Dn9eS1x4h.png" /></figure><p>One <strong>advantage </strong>of having <strong>timestamp </strong>is :</p><p>If we want to get the <strong>date</strong>, then we can write as</p><p><strong>select DATE(empOrStuLogEntry) from empOrStuInformation1</strong></p><p>If we want to get the <strong>time</strong>, then we can write as</p><p><strong>select TIME(empOrStuLogEntry) from empOrStuInformation1</strong></p><p><strong>java.sql.TIME</strong></p><p>create table empOrStuInformation2</p><p>(</p><p>id int NOT NULL AUTO_INCREMENT PRIMARY KEY,</p><p>empOrStuName varchar(20),</p><p>empOrStuAvailability DATE,</p><p>empOrStuLogEntry timestamp,</p><p>empOrStuEntryTime time</p><p>);</p><p>Insert statement via mysql :</p><p>INSERT INTO `test`.`empOrStuInformation2` (`id`, `empOrStuName`, `empOrStuAvailability`, `empOrStuLogEntry`, `empOrStuEntryTime`) VALUES (‘1’, ‘BBBB’, ‘2021–01–01’, ‘2021–01–01 12:50:00’, ‘10:00:00’);</p><p>INSERT INTO `test`.`empOrStuInformation2` (`id`, `empOrStuName`, `empOrStuAvailability`, `empOrStuLogEntry`, `empOrStuEntryTime`) VALUES (‘2’, ‘DDDD’, ‘2021–01–01’, ‘2021–01–01 14:50:00’, ‘10:00:00’);</p><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*NpYMUWfDLDqbepRE.png" /></figure><p>Java way :</p><p>Java</p><pre>import java.sql.Date;<br>import java.sql.Timestamp;<br>import java.sql.Time;<br>String empOrStuAvailableDate = &quot;2021-01-01&quot;;<br>Date utilAvailabilityDate = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;).parse(empOrStuAvailableDate);<br>//jdbc connectivity expects java.sql.Date<br>java.sql.Date sqlAvailabilityDate = new java.sql.Date(utilAvailabilityDate.getTime()); </pre><pre>//create a java timestamp object that represents the current time <br>// (i.e., a &quot;current timestamp&quot;)<br>Calendar calendarInstance = Calendar.getInstance();<br>java.sql.Timestamp sampleJavaTimestampObject = <br>  new java.sql.Timestamp(calendarInstance.getTime().getTime());<br>try{  <br>Class.forName(&quot;com.mysql.jdbc.Driver&quot;);  <br>//Here test is the databasename<br>//username is root and password is root<br>Connection con=DriverManager.getConnection(  <br>&quot;jdbc:mysql://localhost:3306/test&quot;,&quot;root&quot;,&quot;root&quot;);  <br>//Instantiating the Time class<br>Time entryTime = new Time(0L);<br>//Setting time<br>entryTime.setTime(new java.util.Date().getTime());<br> <br>PreparedStatement pStmt=con.prepareStatement(&quot;insert into empOrStuInformation2 <br> (empOrStuName,empOrStuAvailability,empOrStuLogEntry,empOrStuEntryTime) values(?,?,?,?)&quot;);</pre><pre>pStmt.setString(1,&quot;AAAA&quot;);<br>//The setDate() method is used to set date <br>pStmt.setDate(2,sqlAvailabilityDate);<br>//setTimestamp() is used to set timestamp.<br>pStmt.setTimestamp(3, sampleJavaTimestampObject);<br>//setTime() is used to set time.<br>pStmt.setTime(4, entryTime);<br>                                             <br>pStmt.executeUpdate();<br>pStmt.close();<br>con.close(); <br>}catch(Exception ex){ <br>  System.out.println(ex);<br>}  <br>}  <br>}</pre><p>Output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*dESk-ZS2n741mrn0.png" /></figure><p><strong>Conclusion :</strong></p><p>Depends upon the requirement, all 3 functionalities are helpful.</p><p>Java.sql.Date -&gt; Used to record the occurrence, entry, exit etc., without considering the exact time</p><p>Java.sql.Time -&gt; To keep alaram kind of functionalities irrespective of date</p><p>Java.sql.Timestamp-&gt; To log the entries perfectly and will be much helpful to find the nature of each and every entry that occurred in the table and hence much helpful in case of recovery. Using Date() and Time() functions we can explicit Date part and Time part seperately also</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4879f2b816" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Validate SQL Query With Regular Expression?]]></title>
            <link>https://priyarajtt.medium.com/how-to-validate-sql-query-with-regular-expression-b4454f5a13e8?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4454f5a13e8</guid>
            <category><![CDATA[rdbms]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[regular-ex]]></category>
            <category><![CDATA[sql-qu]]></category>
            <category><![CDATA[validation]]></category>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 06:47:11 GMT</pubDate>
            <atom:updated>2022-09-20T06:47:11.664Z</atom:updated>
            <content:encoded><![CDATA[<p>How to Validate SQL Query With Regular Expression?</p><p>Generally, a row of data will consist of email address, phone numbers, alpha/alphanumeric/numeric values, etc., Usually, front end validations are there to validate an email address/phone number, etc., In this article, we will see how it can be validated by using Regular expressions while writing SQL queries. Because always it is good to pass relevant data in the backend. Whenever there is an error in the data, Regular expression quickly validates that and informs the user whether is it a success or failure.</p><p><strong>Step 1:</strong> Create a database</p><p><strong>Query:</strong></p><pre>SELECT * FROM sys.databases WHERE name = &#39;GEEKSFORGEEKS&#39;<br>    BEGIN<br>    CREATE DATABASE [GEEKSFORGEEKS]<br>    END</pre><p><strong>Step 2:</strong> Create “GeekAuthors” table under the “GEEKSFORGEEKS” database</p><p><strong>Query:</strong></p><pre>use GEEKSFORGEEKS<br>CREATE TABLE GeekAuthors (<br>    ID INT IDENTITY NOT NULL PRIMARY KEY,<br>    AuthorName VARCHAR(255) NOT NULL,<br>    AuthorEmail VARCHAR(255) NOT NULL,<br>    Age INT,<br>    Skillsets VARCHAR(255),<br>    NumberOfPosts INT<br>);<br>GO</pre><p>As AuthorEmail is a varchar column, a wrongly invalid email address got entered into the table “GeekAuthors”. Our task is to find out the rows that got an invalid email address.</p><p><strong>Step 3:</strong> To achieve this, let us put sample data in each row</p><pre>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Rachel&#39;,&#39;rachel@gmail.com&#39;,25,&#39;Java,Python,.Net&#39;,5);<br>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Phoebe&#39;,&#39;phoebegmailcom&#39;,22,&#39;Android,Python,.Net&#39;,15);<br>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Monica&#39;,&#39;monica@gmailcom&#39;,23,&#39;IOS,GO,R&#39;,10);<br>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Joey&#39;,&#39;joey@.com&#39;,24,&#39;Java,Python,GO&#39;,5);<br>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Chandler&#39;,&#39;chandler@gmail&#39;,23,&#39;IOS,GO,R&#39;,10);<br>INSERT INTO GeekAuthors (AuthorName,AuthorEmail,Age,Skillsets,NumberOfPosts) <br>VALUES (&#39;Ross&#39;,&#39;ross@gmail.com&#39;,24,&#39;Java,Python,GO&#39;,5);</pre><p><strong>Step 4: </strong>Now we validate the email address.</p><p>We need to validate whether the entered email address is correct or not. For that, we can easily achieve that</p><p><strong>Query:</strong></p><pre>-- Get all email address<br>SELECT AuthorEmail FROM GeekAuthors<br>-- Get ValidEmail Address<br>SELECT AuthorEmail AS ValidEmail<br>FROM GeekAuthors<br>WHERE AuthorEmail LIKE &#39;%_@__%.__%&#39;<br>        AND PATINDEX(&#39;%[^a-z,0-9,@,.,_,\-]%&#39;, AuthorEmail) = 0<br>GO<br>-- use NOT condition in the WHERE clause and select all the invalid emails as well.<br>SELECT AuthorEmail AS NotValidEmail<br>FROM GeekAuthors<br>WHERE NOT AuthorEmail LIKE &#39;%_@__%.__%&#39;<br>        AND PATINDEX(&#39;%[^a-z,0-9,@,.,_,\-]%&#39;, AuthorEmail) = 0<br>GO</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*FQ82uwcwr0yMkAAR.png" /></figure><p><strong>Step 5:</strong> For locating numeric value from the given value using Regular expression. It can be found out by using two ways</p><p>Our input expression may consist of alphanumeric values. In order to find out the position of the numeric value in the data, we can use the below format.</p><p><strong>Query:</strong></p><pre>--pattern to check is: Not of  A-Z (both A-Z and a-z(search pattern))<br>-- in the input string and <br>--finding the position of the non-matching pattern<br>-- As we are checking numeric values, it checks for numeric value position <br>--and it is displaying position of the character<br>Way 1 :<br>SELECT &#39;GeekPremierLeague2022&#39; as ContestName,<br>PATINDEX(&#39;%[^A-Za-z]%&#39;, &#39;GeekPremierLeague2022&#39;) as<br>NumericCharacterPosition;<br>Way 2 :<br>SELECT &#39;GeekPremierLeague2022&#39; as ContestName, <br>PATINDEX(&#39;%[0-9]%&#39;, &#39;GeekPremierLeague2022&#39;) as<br>NumericCharacterPosition;</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*SNr3K0ghi4ykvIiU.png" /></figure><p>In case numeric is not available, we will get 0 as the answer</p><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/0*4J-R_zOVSgA-CkcJ.png" /></figure><p><strong>Step 6: </strong>In a few scenarios, we may need to extract only alphabets (a-z) from the input string.</p><p>It can be possible by combining 2 functions namely PATINDEX and STUFF.</p><ul><li>A regular expression has to be applied on PATINDEX. Using the above query we will get the numeric position</li><li>By using the STUFF function, we can replace all the numeric values.</li></ul><p><strong>Query:</strong></p><pre>-- At the 18th position, one character is replaced. <br>We need to remove numeric value. <br>-- Hence STUFF function is used<br>1st Param -- Input string<br> 2nd Param -- Start location . As numeric is present<br>  at 18th location, here it is given<br> 3rd Param -- Number of characters to be replaced <br> 4th Param - Replacing value<br>SELECT STUFF(&#39;GeekPremierLeague2022&#39;, 18, 1, &#39;&#39; ); <br>-- One character is replaced at the index 18<br>-- If we want to remove all the numeric above<br>SELECT STUFF(&#39;GeekPremierLeague2022&#39;, 18, 4, &#39;&#39; ); <br>-- Four characters are replaced starting from  the index 18</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/0*D3nm7xBqAj_m8PTj.png" /></figure><p>Hence by applying both PATINDEX and STUFF, we can remove the numeric value in the given string:</p><p><strong>Query:</strong></p><pre>-- Below code will produce only alpha text only<br>-- Scenario: A column is created in a table to accept<br>   only alphabets. As there is no direct way available, <br>-- we can use this approach and extract the alphabets alone<br>DECLARE @inputData NVARCHAR(MAX) = &#39;GEEKS PREMIER LEAGUE 2022&#39;       <br>--input string<br>DECLARE @intPosition INT    <br> --get the position of the integer from the input string   <br>SET @intPosition = PATINDEX(&#39;%[^A-Za-z]%&#39;, @inputData) <br>-- We can use PATINDEX(&#39;%[0-9]%&#39;) also<br>print @intPosition<br>--run loop until no integer is found in the input string<br>WHILE @intPosition &gt; 0                                     <br>  BEGIN  <br>     --remove the integer from that position<br>    SET @inputData = STUFF(@inputData, @intPosition, 1, &#39;&#39; )   <br>    --PRINT @inputData <br>    SET @intPosition = PATINDEX(&#39;%[^A-Za-z]%&#39;, @inputData )<br>    --Again get the position of the next integer in the input string<br>    --PRINT @intPosition <br>END  <br>SELECT &#39;GEEKS PREMIER LEAGUE 2022&#39; as InputString, @inputData AS AlphabetsOnly</pre><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*8noQsLkLZdFQUapZ.jpg" /></figure><p><strong>Step 7: </strong>To get the numeric values alone suppose when the data feed is occurring that consists of employee name, phone number, address, and email id, we can use the below approach to retrieve the phone number (i.e. numeric value) in the below way.</p><p><strong>Query:</strong></p><pre>DECLARE @inputString  VARCHAR(MAX)<br>DECLARE @validchars VARCHAR(MAX)</pre><pre>SET @inputString  = &#39;GeekAuthor1 123456789 Address1 geek@gmail.com&#39;<br>--We are going to take continuous set of numbers<br> and it should not have any spaces also in between<br>SET @validchars = &#39;[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]&#39;<br>DECLARE @idx INT<br>SET @idx = PATINDEX(&#39;%&#39;+ @validchars +&#39;%&#39;,@inputString )<br>IF @idx &gt; 0 AND <br>    (@idx = LEN(@inputString )-8<br>    OR PATINDEX(SUBSTRING(@inputString ,@idx+9,1),&#39;[0-9]&#39;)=0)<br>    SET @inputString =SUBSTRING(@inputString,<br>    PATINDEX(&#39;%&#39;+ @validchars +&#39;%&#39;,@inputString ), 9)<br>ELSE SET @inputString  = &#39;&#39;<br>SELECT @inputString as NumericAlone</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/0*_gUV7fmgKom9baLC.jpg" /></figure><p>Hence Regular expressions are used in many places for validating an email, address, validating alpha alone, or validating numeric alone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4454f5a13e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regular Expression to Extract SQL Query]]></title>
            <link>https://priyarajtt.medium.com/regular-expression-to-extract-sql-query-94e1989c7014?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/94e1989c7014</guid>
            <category><![CDATA[sql-queries]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[extraction]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 06:44:53 GMT</pubDate>
            <atom:updated>2022-09-20T06:44:53.102Z</atom:updated>
            <content:encoded><![CDATA[<p>Regular Expressions are the easier mechanism to search the data that matches the complex criteria. For example, from an alphanumeric value, extract only the alpha value or numeric value or check for the specific patterns of character matching and retrieve the records, etc.</p><p>Let us see them one by one by taking some sample scenarios;</p><p><strong>Step 1:</strong> Creating Database</p><p><strong>Query:</strong></p><pre>SELECT * FROM sys.databases WHERE name = &#39;GEEKSFORGEEKS&#39;<br>    BEGIN<br>    CREATE DATABASE [GEEKSFORGEEKS]<br>    END</pre><p><strong>Step 2: </strong>Using the database</p><p><strong>Query:</strong></p><pre>USE GEEKSFORGEEKS</pre><p><strong>Step 3:</strong> CREATING TABLE Country under GEEKSFORGEEKS and insert few records</p><p><strong>Query:</strong></p><pre>INSERT INTO Country(CountryID,CountryName) VALUES (1,&#39;United States&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (2,&#39;United States&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (3,&#39;United Kingdom&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (4,&#39;Canada&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (5,&#39;United Kingdom&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (6,&#39;Canada&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (7,&#39;United States&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (8,&#39;Australia&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (9,&#39;Canada&#39;);<br>INSERT INTO Country(CountryID,CountryName) VALUES (10,&#39;United States&#39;);</pre><pre>SELECT * FROM Country</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*ysVeYO4zRUgRNnSy.png" /></figure><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/0*2hDDuT0XaAWzMu4s.png" /></figure><p><strong>Example 1:</strong></p><p>To get the records starting between A — D and the second letter between U to Z and the rest of the letters can be anything.</p><p><strong>Query:</strong></p><pre>--Find Country Names having:<br>--First character should be A and D alphabets. <br>--The second character should be from U and Z alphabet<br>SELECT * FROM Country<br>WHERE CountryName like &#39;[A-D][U-Z]%&#39; <strong> </strong><br>--regular expession is used here</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*H_yUSe5Hd_EHptbH.png" /></figure><p>If we need to specifically check for the first character alone and the rest of the characters can be anything, then</p><p><strong>Query:</strong></p><pre>--Find Country Names having:<br>--First character should be A and D alphabets. <br>--Rest letters can be any character<br>SELECT * FROM Country<br>WHERE CountryName like &#39;[A-D]%&#39; <br>--regular expession<br></pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*AxCbxgE8Jpyw73Uf.png" /></figure><p>By seeing the above two outputs, we can understand that just by giving different regular expressions, we are getting different outputs.</p><p>Suppose if we want to find country names starting with ‘U’ alone then the query will be as follows:</p><p><strong>Query:</strong></p><pre>--Find country names starting with &#39;U&#39; alone<br>SELECT * FROM Country<br>WHERE CountryName like &#39;U%&#39;  <br>--regular expession</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*spnnTEedDnKVOojP.png" /></figure><p>Suppose if we want to find country names starting with ‘U’ and additional information then the query will be as follows:</p><p><strong>Query:</strong></p><pre>--Find country names starting with<br>-- U and additonal condition is given<br>SELECT * FROM Country<br>WHERE CountryName like &#39;U% [S]%&#39;<br>--regular expession</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*84DP9jBKfmuCUAuG.png" /></figure><p>While using with Like operator, we need to understand the below factors also</p><p><strong>Wildcard characterDescription</strong>%A string of 0 or more characters will be retrieved[ ]Within the specified range, any single character alone will be retrieved[^]Within the specified range, none of the characters will be retrieved</p><p>We can use the regular expression in other functions also.</p><p><strong>Example 2:</strong></p><p>Let us check out PATINDEX function first. It is a function that accepts the search pattern and input string and returns the starting position of the character not matching the pattern.</p><pre>--pattern to check is <strong>A-Z or a-z(search pattern)</strong><br><strong>-- in the input strin</strong>g and <br>--position of the <strong>non-matching pattern</strong><br>-- It checks for numeric value position <br>--and it is displaying position of the character<br>SELECT &#39;GFGVersion1&#39; as InputString,<br>PATINDEX(&#39;%[^A-Za-z]%&#39;, &#39;GFGVersion1&#39;) as<br>NumericCharacterPosition;</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*l3Jvw6b0Uy7j3IXE.png" /></figure><p>To get numbers only from an input string, we can use in below way also</p><pre>SELECT &#39;GFGVersion1&#39; as InputString, <br>PATINDEX(&#39;%[0-9]%&#39;, &#39;GFGVersion1&#39;) as<br>NumericCharacterPosition;</pre><p>i.e. instead of using [^A-Za-z], used [0–9] and getting the same result as above</p><pre>-- 0 will indicate no numeric value present<br>SELECT &#39;VERSION&#39; as InputString, <br>PATINDEX(&#39;%[^A-Za-z]%&#39;, &#39;VERSION&#39;)<br> as NumericPosition;</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*91RGo0Idcnc9vsHZ.png" /></figure><p>We can use this functionality of using a regular expression with functions like PATINDEX, we can solve to get only the characters alone from input string/numbers alone from input string etc.,</p><p>For that, let us see STUFF function also</p><p><strong>STUFF function</strong></p><pre>--remove the integer from<br> -- position 3 in the input string. <br> /* As only one character need to be removed, <br> we need to send params like this<br> 1st Param -- Input string<br> 2nd Param -- Start location <br> 3rd Param -- Number of characters to be replaced<br> 4th Param - Replacing value<br> */<br>SELECT STUFF(&#39;GE098EKS9VER1&#39;, 3, 1, &#39;&#39; );</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*u0TNEQrnhrdG1evg.png" /></figure><p><strong>Example 3 :</strong></p><p>By having PATINDEX and STUFF functions, we can get only the character values from an input string.</p><ul><li>We need to use a regular expression to get applied on PATINDEX</li><li>Find out the numeric position and remove the numbers by using STUFF function</li><li>Step 2 has to be repeated until there is no numeric value</li></ul><p><strong>Query:</strong></p><pre>DECLARE @inputData NVARCHAR(MAX) = &#39;GE098EKS9VER1&#39;       <br>--input string<br>DECLARE @intPosition INT    <br> --get the position of the integer from the input string   <br>SET @intPosition = PATINDEX(&#39;%[^A-Za-z]%&#39;, @inputData)    <br>print @intPosition</pre><pre>--run loop until no integer is found in the input string<br>WHILE @intPosition &gt; 0                                     <br>  BEGIN  <br>     --remove the integer from that position<br>    SET @inputData = STUFF(@inputData, @intPosition, 1, &#39;&#39; )   <br>    --PRINT @inputData <br>    SET @intPosition = PATINDEX(&#39;%[^A-Za-z]%&#39;, @inputData )<br>    --Again get the position of the next integer in the input string<br>    --PRINT @intPosition <br>END  <br>SELECT &#39;GE098EKS9VER1&#39; as InputString, @inputData AS AlphabetsOnly</pre><p><strong>Output :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*SklF27L2yyLcdEZG.png" /></figure><p>Similarly, we can use regular expression as the best search pattern practice.</p><p>Throughout SQL, we can use a regular expression to extract different outputs to our needs. It can be used with other functions also and it will help to get only alphabets from an input string/numerals from an input string.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94e1989c7014" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Spring Boot Microservices Sample Project]]></title>
            <link>https://priyarajtt.medium.com/java-spring-boot-microservices-sample-project-ebd93badd15f?source=rss-5563f4a98b2d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebd93badd15f</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-spring-boot]]></category>
            <category><![CDATA[java-microservices]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[priya raj]]></dc:creator>
            <pubDate>Mon, 19 Sep 2022 05:56:04 GMT</pubDate>
            <atom:updated>2022-09-19T05:56:04.509Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.geeksforgeeks.org/microservices-introduction/">Microservices </a>are more popular nowadays. They can be written in any language. In this article, let us see <a href="https://www.geeksforgeeks.org/introduction-to-spring-boot/">Spring Boot</a> Microservices. in this article let us see a base project “currency-exchange-sample-service” which has a business logic and which can be invoked in another project “<strong>currency-conversion-sample-servicce</strong>”. Both are Maven projects and let us see them one by one.</p><p><strong>Microservice 1: currency-exchange-sample-service</strong></p><p><strong>Project Structure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*hGHTKKmhryIYmyTN.gif" /></figure><p><strong>pom.xml</strong></p><p>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;project xmlns=”<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>&quot; <br> xmlns:xsi=”<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br> xsi:schemaLocation=”<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <br> <a href="https://maven.apache.org/xsd/maven-4.0.0.xsd">https://maven.apache.org/xsd/maven-4.0.0.xsd</a>&quot;&gt;<br> &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br> &lt;parent&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br> &lt;version&gt;2.2.1.RELEASE&lt;/version&gt;<br> &lt;relativePath/&gt; &lt;! — lookup parent from repository →<br> &lt;/parent&gt;<br> &lt;groupId&gt;com.gfg.microservices&lt;/groupId&gt;<br> &lt;artifactId&gt;currency-exchange-sample-service&lt;/artifactId&gt;<br> &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br> &lt;name&gt;currency-exchange-sample-service&lt;/name&gt;<br> &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;</p><p>&lt;properties&gt;<br> &lt;java.version&gt;1.8&lt;/java.version&gt;<br> &lt;spring-cloud.version&gt;Hoxton.RC2&lt;/spring-cloud.version&gt;<br> &lt;/properties&gt;</p><p>&lt;dependencies&gt;<br> <br> &lt;! — Starter for building web, including RESTful, <br> applications using Spring MVC. →<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;<br> &lt;/dependency&gt;<br> &lt;! — The spring-boot-devtools module can be included in any <br> project to provide additional development-time features →<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;<br> &lt;scope&gt;runtime&lt;/scope&gt;<br> &lt;optional&gt;true&lt;/optional&gt;<br> &lt;/dependency&gt;<br> &lt;! — H2 is an open-source lightweight Java database →<br> &lt;dependency&gt;<br> &lt;groupId&gt;com.h2database&lt;/groupId&gt;<br> &lt;artifactId&gt;h2&lt;/artifactId&gt; <br> &lt;scope&gt;runtime&lt;/scope&gt; <br> &lt;/dependency&gt; <br> &lt;! — starter for using Spring Data JPA with Hibernate. →<br> &lt;dependency&gt; <br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt; <br> &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt; <br> &lt;version&gt;2.1.3.RELEASE&lt;/version&gt; <br> &lt;/dependency&gt; <br> &lt;! — provides secured endpoints for monitoring <br> and managing your Spring Boot application →<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;<br> &lt;scope&gt;test&lt;/scope&gt;<br> &lt;exclusions&gt;<br> &lt;exclusion&gt;<br> &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;<br> &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;<br> &lt;/exclusion&gt;<br> &lt;/exclusions&gt;<br> &lt;/dependency&gt;<br> &lt;/dependencies&gt;</p><p>&lt;dependencyManagement&gt;<br> &lt;dependencies&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;<br> &lt;version&gt;${spring-cloud.version}&lt;/version&gt;<br> &lt;type&gt;pom&lt;/type&gt;<br> &lt;scope&gt;import&lt;/scope&gt;<br> &lt;/dependency&gt;<br> &lt;/dependencies&gt;<br> &lt;/dependencyManagement&gt;</p><p>&lt;build&gt;<br> &lt;plugins&gt;<br> &lt;plugin&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;<br> &lt;/plugin&gt;<br> &lt;/plugins&gt;<br> &lt;/build&gt;</p><p>&lt;repositories&gt;<br> &lt;repository&gt;<br> &lt;id&gt;spring-milestones&lt;/id&gt;<br> &lt;name&gt;Spring Milestones&lt;/name&gt;<br> &lt;url&gt;<a href="https://repo.spring.io/milestone">https://repo.spring.io/milestone</a>&lt;/url&gt;<br> &lt;/repository&gt;<br> &lt;/repositories&gt;</p><p>&lt;/project&gt;</p><p>Let us see the important files</p><p><strong>CurrencyExchangeServiceSampleApplication.java</strong></p><p>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;</p><p><a href="http://twitter.com/SpringBootApplicatio"><strong>@SpringBootApplicatio</strong></a><strong>n<br>// It is equivalent to using </strong><a href="http://twitter.com/Configuration"><strong>@Configuration</strong></a><strong>,<br>// </strong><a href="http://twitter.com/EnableAutoConfigurat"><strong>@EnableAutoConfigurat</strong></a><strong>ion and </strong><a href="http://twitter.com/ComponentScan"><strong>@ComponentScan</strong></a><strong> with their<br>// default attributes:<br>public class CurrencyExchangeServiceSampleApplication {</strong></p><p><strong>public static void main(String[] args)<br> {<br> SpringApplication.run(<br> CurrencyExchangeServiceSampleApplication.class,<br> args);<br> }<br>}</strong></p><h3><strong><em>CurrencyExchangeSampleController.java</em></strong></h3><pre>@GetMapping(&quot;/currency-exchange-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}&quot;) <br>// where {fromCurrency} and {toCurrency} are path variable<br>// fromCurrency can be USD,EUR,AUD,INR and toCurrency can be the opposite of any fromCurrency</pre><h4><strong>import java.math.BigDecimal;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.core.env.Environment;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.RestController;</strong></h4><h4><strong>@SpringBootApplication<br>@RestController<br>// The @RestController annotation in Spring is essentially<br>// just a combination of<br>// @Controller and @ResponseBody. This annotation was added<br>// during Spring 4.0 to remove the redundancy of declaring<br>// the @ResponseBody annotation in your controller<br>public class CurrencyExchangeSampleController {<br> @Autowired private Environment environment;</strong></h4><h4>@GetMapping(<br> &quot;/currency-exchange-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}&quot;)<br> // where {fromCurrency} and {toCurrency} are path<br> // variable<br> // fromCurrency can be USD,EUR,AUD,INR and toCurrency<br> // can be the opposite of any fromCurrency<br> public ExchangeValue<br> retrieveExchangeValue(@PathVariable String fromCurrency,<br> @PathVariable String toCurrency)<br> {<br> // Here we need to write all of our business logic<br> BigDecimal conversionMultiple = null;<br> ExchangeValue exchangeValue = new ExchangeValue();<br> if (fromCurrency != null &amp;&amp; toCurrency != null) {<br> if (fromCurrency.equalsIgnoreCase(&quot;USD&quot;)<br> &amp;&amp; toCurrency.equalsIgnoreCase(&quot;INR&quot;)) {<br> conversionMultiple = BigDecimal.valueOf(78);<br> }<br> if (fromCurrency.equalsIgnoreCase(&quot;INR&quot;)<br> &amp;&amp; toCurrency.equalsIgnoreCase(&quot;USD&quot;)) {<br> conversionMultiple<br> = BigDecimal.valueOf(0.013);<br> }<br> if (fromCurrency.equalsIgnoreCase(&quot;EUR&quot;)<br> &amp;&amp; toCurrency.equalsIgnoreCase(&quot;INR&quot;)) {<br> conversionMultiple = BigDecimal.valueOf(82);<br> }<br> if (fromCurrency.equalsIgnoreCase(&quot;AUD&quot;)<br> &amp;&amp; toCurrency.equalsIgnoreCase(&quot;INR&quot;)) {<br> conversionMultiple = BigDecimal.valueOf(54);<br> }<br> }<br> // setting the port<br> exchangeValue = new ExchangeValue(<br> 1000L, fromCurrency, toCurrency,<br> conversionMultiple);<br> exchangeValue.setPort(Integer.parseInt(<br> environment.getProperty(&quot;local.server.port&quot;)));<br> return exchangeValue;<br> }<br>}</h4><h3><strong>application.properties</strong></h3><pre><strong>spring.application.name=currency-exchange-sample-service<br>server.port=8000 #Representation of the port number . We can set different port number in run configuration also<br>spring.jpa.show-sql=true  #To display the SQL<br>spring.h2.console.enabled=true  <br>spring.datasource.platform=h2  #As we are using h2 datasource <br>spring.datasource.url=jdbc:h2:mem:gfg</strong></pre><h3><strong>data.sql</strong></h3><pre>insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)  <br>values(10001,&#39;USD&#39;, &#39;INR&#39; ,65,0);  <br>insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)  <br>values(10002,&#39;EUR&#39;, &#39;INR&#39; ,82,0);  <br>insert into exchange_value(id,currency_from,currency_to,conversion_multiple,port)  <br>values(10003,&#39;AUD&#39;, &#39;INR&#39; ,53,0);</pre><p>By default, it has been set to run on port 8000. We can create another instance and can make the project run on port 8001 in the below ways</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*8ROZRze8IhxMTutw.gif" /></figure><p>As this is the spring boot application, it can be normally run as Java application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*Q4IvzlSJj6BdrcR_.gif" /></figure><p>If we set to run the application on two different ports, we will get the below options</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/0*OApkQJRHUTUOMWPr.gif" /></figure><p>Let us select the first one. On running the application, in the console, we see as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*NwJATZIbYefyFTaP.gif" /></figure><p>From the console, we can see that it used default Tomcat and the project is running on port 8080. As we have used 3 insert scripts, automatically table is created and the data is inserted. We can able to do the following</p><h3>http://localhost:8000/currency-exchange-sample/fromCurrency/USD/toCurrency/INR</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/0*C8tQ5Byl9qMC-I1E.gif" /></figure><p>When this URL is hit, it will be redirected to the controller, and fromCurrency is taken as “USD” and toCurrency is taken as “INR”</p><p>Because of this,</p><pre>// Below set of code is executed and hence we are seeing the result like above<br>if (fromCurrency != null &amp;&amp; toCurrency != null) {<br>			if (fromCurrency.equalsIgnoreCase(&quot;USD&quot;) &amp;&amp; toCurrency.equalsIgnoreCase(&quot;INR&quot;)) {<br>				conversionMultiple = BigDecimal.valueOf(78);<br>			}</pre><pre>Similarly, we can able to execute the below following URLs</pre><h3><a href="http://localhost:8000/currency-exchange-sample/fromCurrency/EUR/toCurrency/INR"><strong>http://localhost:8000/currency-exchange-sample/fromCurrency/EUR/toCurrency/INR</strong></a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*V4Ckoxvf2BhWmxgA.gif" /></figure><h3><a href="http://localhost:8000/currency-exchange-sample/fromCurrency/AUD/toCurrency/INR">http://localhost:8000/currency-exchange-sample/fromCurrency/AUD/toCurrency/INR</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*4NFjgVSG3J91de5h.gif" /></figure><p>Hence according to our business needs, we can add business logic to the controller file. Let us see how the above service is getting called in the currency-conversion project</p><h3><strong>Microservice 2:</strong>currency-conversion-sample-service</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*Z4IS23VkBPSLkVo3.gif" /></figure><p>This is also a maven project</p><h3>pom.xml</h3><p>&lt;?xml version=”1.0&quot; encoding=”UTF-8&quot;?&gt;<br>&lt;project xmlns=”<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a>&quot;<br> xmlns:xsi=”<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>&quot;<br> xsi:schemaLocation=”<a href="http://maven.apache.org/POM/4.0.0">http://maven.apache.org/POM/4.0.0</a> <br> <a href="https://maven.apache.org/xsd/maven-4.0.0.xsd">https://maven.apache.org/xsd/maven-4.0.0.xsd</a>&quot;&gt;<br> &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br> &lt;parent&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br> &lt;version&gt;2.2.1.RELEASE&lt;/version&gt;<br> &lt;relativePath/&gt; <br> &lt;/parent&gt;<br> &lt;groupId&gt;com.gfg.microservices&lt;/groupId&gt;<br> &lt;artifactId&gt;currency-conversion-sample-servicce&lt;/artifactId&gt;<br> &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;<br> &lt;name&gt;currency-conversion-servicce&lt;/name&gt;<br> &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;</p><p>&lt;properties&gt;<br> &lt;java.version&gt;1.8&lt;/java.version&gt;<br> &lt;spring-cloud.version&gt;Hoxton.RC2&lt;/spring-cloud.version&gt;<br> &lt;/properties&gt;</p><p>&lt;dependencies&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-cloud-starter-config&lt;/artifactId&gt;<br> &lt;/dependency&gt;</p><p>&lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;<br> &lt;scope&gt;runtime&lt;/scope&gt;<br> &lt;optional&gt;true&lt;/optional&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;<br> &lt;scope&gt;test&lt;/scope&gt;<br> &lt;exclusions&gt;<br> &lt;exclusion&gt;<br> &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;<br> &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;<br> &lt;/exclusion&gt;<br> &lt;/exclusions&gt;<br> &lt;/dependency&gt;<br> &lt;/dependencies&gt;</p><p>&lt;dependencyManagement&gt;<br> &lt;dependencies&gt;<br> &lt;dependency&gt;<br> &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-cloud-dependencies&lt;/artifactId&gt;<br> &lt;version&gt;${spring-cloud.version}&lt;/version&gt;<br> &lt;type&gt;pom&lt;/type&gt;<br> &lt;scope&gt;import&lt;/scope&gt;<br> &lt;/dependency&gt;<br> &lt;/dependencies&gt;<br> &lt;/dependencyManagement&gt;</p><p>&lt;build&gt;<br> &lt;plugins&gt;<br> &lt;plugin&gt;<br> &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br> &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;<br> &lt;/plugin&gt;<br> &lt;/plugins&gt;<br> &lt;/build&gt;</p><p>&lt;repositories&gt;<br> &lt;repository&gt;<br> &lt;id&gt;spring-milestones&lt;/id&gt;<br> &lt;name&gt;Spring Milestones&lt;/name&gt;<br> &lt;url&gt;<a href="https://repo.spring.io/milestone">https://repo.spring.io/milestone</a>&lt;/url&gt;<br> &lt;/repository&gt;<br> &lt;/repositories&gt;</p><p>&lt;/project&gt;</p><p>Main important java files</p><p><strong>CurrencyConversionSampleServiceApplication.java</strong></p><p>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;</p><p><a href="http://twitter.com/SpringBootApplicatio">@SpringBootApplicatio</a>n<br>public class CurrencyConversionSampleServiceApplication {<br> public static void main(String[] args) {<br> SpringApplication.run(CurrencyConversionSampleServiceApplication.class, args);<br> }<br>}</p><p><strong>CurrencyConversionSampleBean.java</strong></p><p>import java.math.BigDecimal;</p><p>public class CurrencyConversionSampleBean {<br> // We need to set all the fields that is going to<br> // received in response<br> private Long id;<br> private String from;<br> private String to;<br> private BigDecimal ConversionMultiple;<br> private BigDecimal quantity;<br> private BigDecimal totalCalculatedAmount;<br> private int port;</p><p>// default constructor<br> public CurrencyConversionSampleBean() {}</p><p>// creating constructor<br> public CurrencyConversionSampleBean(<br> Long id, String from, String to,<br> BigDecimal conversionMultiple, BigDecimal quantity,<br> BigDecimal totalCalculatedAmount, int port)<br> {<br> super();<br> this.id = id;<br> this.from = from;<br> this.to = to;<br> ConversionMultiple = conversionMultiple;<br> this.quantity = quantity;<br> this.totalCalculatedAmount = totalCalculatedAmount;<br> this.port = port;<br> }</p><p>// creating setters and getters<br> public Long getId() { return id; }</p><p>public void setId(Long id) { this.id = id; }</p><p>public String getFrom() { return from; }</p><p>public void setFrom(String from) { this.from = from; }</p><p>public String getTo() { return to; }</p><p>public void setTo(String to) { this.to = to; }</p><p>public BigDecimal getConversionMultiple()<br> {<br> return ConversionMultiple;<br> }</p><p>public void<br> setConversionMultiple(BigDecimal conversionMultiple)<br> {<br> ConversionMultiple = conversionMultiple;<br> }</p><p>public BigDecimal getQuantity() { return quantity; }</p><p>public void setQuantity(BigDecimal quantity)<br> {<br> this.quantity = quantity;<br> }</p><p>public BigDecimal getTotalCalculatedAmount()<br> {<br> return totalCalculatedAmount;<br> }</p><p>public void setTotalCalculatedAmount(<br> BigDecimal totalCalculatedAmount)<br> {<br> this.totalCalculatedAmount = totalCalculatedAmount;<br> }</p><p>public int getPort() { return port; }</p><p>public void setPort(int port) { this.port = port; }<br>}</p><p><strong>CurrencyConversionSampleController.java</strong></p><pre>@GetMapping(&quot;/currency-converter-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}/quantity/{quantity}&quot;)</pre><pre>package com.gfg.microservices.currencyconversionservice;</pre><pre>import java.math.BigDecimal;<br>import java.util.HashMap;<br>import java.util.Map;<br>import org.springframework.http.ResponseEntity;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.RestController;<br>import org.springframework.web.client.RestTemplate;</pre><pre>// To invoke an external service, RestTemplate() constructor<br>// is used<br><a href="http://twitter.com/RestController">@RestController</a><br>public class CurrencyConversionSampleController {<br>    <a href="http://twitter.com/GetMapping">@GetMapping</a>(<br>        &quot;/currency-converter-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}/quantity/{quantity}&quot;)<br>    // where {from} and {to} represents the<br>    // column<br>    // returns a bean back<br>    public CurrencyConversionSampleBean<br>    convertCurrency(<a href="http://twitter.com/PathVariable">@PathVariable</a> String fromCurrency,<br>                    <a href="http://twitter.com/PathVariable">@PathVariable</a> String toCurrency,<br>                    <a href="http://twitter.com/PathVariable">@PathVariable</a> BigDecimal quantity)<br>    {</pre><pre>// setting variables to currency exchange service<br>        Map&lt;String, String&gt; uriVariables = new HashMap&lt;&gt;();<br>        // urlParams should match properly<br>        uriVariables.put(&quot;fromCurrency&quot;, fromCurrency);<br>        uriVariables.put(&quot;toCurrency&quot;, toCurrency);<br>        // calling the currency-exchange-sample-service<br>        // <a href="http://localhost:8000/currency-exchange-sample/fromCurrency/%7BfromCurrency%7D/toCurrency/%7BtoCurrency">http://localhost:8000/currency-exchange-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency</a>}<br>        // is the service that got called from part 1. Its<br>        // response is received and via<br>        // CurrencyConversionSampleBean we are getting the<br>        // results back<br>        ResponseEntity&lt;CurrencyConversionSampleBean&gt;<br>            responseEntity<br>            = new RestTemplate().getForEntity(<br>                &quot;<a href="http://localhost:8000/currency-exchange-sample/fromCurrency/%7BfromCurrency%7D/toCurrency/%7BtoCurrency">http://localhost:8000/currency-exchange-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency</a>}&quot;,<br>                CurrencyConversionSampleBean.class,<br>                uriVariables);<br>        CurrencyConversionSampleBean response<br>            = responseEntity.getBody();<br>        // creating a new response bean and getting the<br>        // response back and taking it into Bean Hence the<br>        // output bean should have all the fields that is<br>        // received from the response<br>        return new CurrencyConversionSampleBean(<br>            response.getId(), fromCurrency, toCurrency,<br>            response.getConversionMultiple(), quantity,<br>            quantity.multiply(<br>                response.getConversionMultiple()),<br>            response.getPort());<br>    }<br>}</pre><pre>That is this project is started on port 8100. Now we can able to execute the following URLS</pre><h3><a href="http://localhost:8100/currency-converter-sample/fromCurrency/USD/toCurrency/INR/quantity/1000">http://localhost:8100/currency-converter-sample/fromCurrency/USD/toCurrency/INR/quantity/1000</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*ApkVoxETtxTEAoXG.gif" /></figure><p>When this service is called, it will in turn invoke.</p><p><strong>Assumption:</strong> currency-exchange-sample is running in port 8000 and it produces the required response</p><h3><a href="http://localhost:8000/currency-exchange-sample/fromCurrency/USD/toCurrency/INR">http://localhost:8000/currency-exchange-sample/fromCurrency/USD/toCurrency/INR</a></h3><p>And then as the logic is written as</p><pre>ResponseEntity&lt;CurrencyConversionSampleBean&gt;responseEntity=new RestTemplate().getForEntity(&quot;http://localhost:8000/currency-exchange-sample/fromCurrency/{fromCurrency}/toCurrency/{toCurrency}&quot;,CurrencyConversionSampleBean.class, uriVariables);<br>		CurrencyConversionSampleBean response=responseEntity.getBody();  <br>		// creating a new response bean and getting the response back and taking it into Bean<br>		// Hence the output bean should have all the fields that is received from the response<br>		return new CurrencyConversionSampleBean(response.getId(), fromCurrency,toCurrency,response.getConversionMultiple(), quantity,quantity.multiply(response.getConversionMultiple()),response.getPort());</pre><p>We are seeing the totalCalculatedAmount as 78 * 1000 i.e. 78000. We are getting “conversionMultiple” from the first URL and it is multiplied with the quantity value here. It is very ideal that, we no need to carry exchange service logic into this application i.e. part 1 project can be separate and part 2 project can invoke part 1 URLs here. So microservices can run separately and other services can use them. Rest of the URLs that can be checked</p><p><strong>Example</strong></p><h3>http://localhost:8100/currency-converter-sample/fromCurrency/EUR/toCurrency/INR/quantity/5000</h3><p>This will call in turn</p><h3>http://localhost:8000/currency-exchange-sample/fromCurrency/EUR/toCurrency/INR</h3><p>And the output will be</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/0*WTFDHux-DrF4kR18.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebd93badd15f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>