<?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 Mujawar Faiyaz Aziz on Medium]]></title>
        <description><![CDATA[Stories by Mujawar Faiyaz Aziz on Medium]]></description>
        <link>https://medium.com/@mujawar.faiyaz.aziz?source=rss-f270e797b6ad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*24H3XcslD-Wi7RSkfwiqeg.jpeg</url>
            <title>Stories by Mujawar Faiyaz Aziz on Medium</title>
            <link>https://medium.com/@mujawar.faiyaz.aziz?source=rss-f270e797b6ad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:16:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mujawar.faiyaz.aziz/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[Java and the Databases, Part I]]></title>
            <link>https://medium.com/@mujawar.faiyaz.aziz/java-and-the-databases-part-i-9866c4fb2d46?source=rss-f270e797b6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/9866c4fb2d46</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jdbc]]></category>
            <dc:creator><![CDATA[Mujawar Faiyaz Aziz]]></dc:creator>
            <pubDate>Tue, 14 Jul 2020 11:30:56 GMT</pubDate>
            <atom:updated>2020-07-14T18:12:35.982Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eVQGKMOtn4oRCs0yB62nUg.jpeg" /></figure><p>Hey guys! Hope you all are safe and healthy in this dreadful pandemic! To help you be productive and engaged, here’s another <em>how-to </em>blog! Today, we gonna be connecting a Java program with SQL databases.</p><h3>Why connect applications with database?</h3><p>In most of modern applications — be it the music players in mobile phones, or gigantic data centers of Google, databases are eminent. Therefore, having the knowledge of databases is crucial for developers. Moreover, connecting an program with database can open up a plethora of real-world applications!</p><p>So, why Java for this blog? The answer is, stated simply, Java is the one of the most popular programming languages present, and yet, easy to start with. Hence, knowing how to connect a Java program to database can be beneficial to anyone.</p><h3>Before we start…</h3><p>Before we start writing the program, I would like to specify a few things.</p><p>First, we would be writing a program that connects, and of course interacts, with a <strong>MySQL </strong>database. I’ve chosen to go with MySQL as it is open-source and is an SQL database.</p><p>Secondly, what we would be doing is writing a program to perform <strong>CRUD </strong>operations on an “<strong>employee</strong>”<strong> </strong>table, a classic example used when teaching databases!</p><p>This is going to be a very simple programming, meant to demonstrate how to connect a Java program with database. It may not follow the best practices for writing a Java program!</p><p>So,ready to start?</p><h3>A short introduction to SQL databases</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*a4T1_FdJtx6-ZEvd3cmaqA.png" /><figcaption>MySQL table representation</figcaption></figure><p>SQL databases are also known as “<strong>Relational Databases</strong>”. These databases store data in the form of tables, or “<strong>relations</strong>” as suggested by the name. Each row in the table represents a relation and the columns represent the properties of the relation. Each row has a unique property, called the <strong>primary key</strong>, by which it is recognized in the table.</p><p><strong>Note:</strong> I assume that you have installed MySQL on your system, and have some experience working with MySQL. If not, you can install MySQL on your system and learn basic operations on MySQL from <a href="https://www.tutorialspoint.com/mysql/index.htm">here</a>.</p><h3>The setup</h3><p>Before we can start writing a program to connect Java with MySQL, we need to download the MySQL connector for Java and add it to the classpath. You can download MySQL connector from <a href="https://dev.mysql.com/downloads/connector/j/">here</a>. To set up the classpath:</p><ul><li><strong>Linux users: </strong>Add the following line to your .bashrc or .profile file:</li></ul><pre>export CLASSPATH=&quot;.:/path/to/mysql-connector-java-version.jar&quot;</pre><ul><li><strong>Windows users:</strong> You can follow the steps <a href="https://www.w3resource.com/mysql/mysql-java-connection.php">here</a>.</li></ul><p>Keep going!</p><h3>Let the show begin!</h3><blockquote><strong>Note</strong>: All the code snippets shown below are images, so you need to write them all yourself instead of just copying and pasting them!</blockquote><p>Alright then, let’s start! Type the following commands to create a folder for the project:</p><pre>mkdir JDBC<br>cd JDBC</pre><p>Create a file named “<strong>JdbcDemo.java</strong>” (of course you can name your file anything you wish!) in your project folder and write the following code into it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Gfl0xy7G0G95LsCNhNkOQ.png" /><figcaption>Starting file for our program — JdbcDemo.java.</figcaption></figure><p><strong><em>Note</em></strong><em>: Replace the dbURL, username and password as per yours!</em></p><p>Guys, don’t be overwhelmed seeing so much of code in just the starting file! Remember — <em>Starting step is always the hardest!</em></p><p>We’ll be taking in all that code slowly! JDBC (Java Database Connectivity) has 6 stages, four of which are as follows :</p><ul><li><strong>Stage I - Registering the driver : </strong>In this stage, we first register with JVM, the driver we will be using to connect to the database, so it can be loaded into the memory. In this example, we will be using <strong>com.mysql.jdbc.cj.Driver</strong> which is provided by Oracle for MySQL. Please note, in most of the tutorials online for JDBC, the driver used will be <strong>com.mysql.jdbc.Driver </strong>. <strong>com.mysql.jdbc.cj.Driver </strong>is the updated version of the same driver.</li><li><strong>Stage II - Connecting to the database : </strong>After having registered the driver, the next step is to connect to database. The <strong>getConnection() </strong>method of DriverManager class requires three parameters: a connection string of the form : jdbc:mysql:localhost:3306/&lt;db_name&gt; , the username of a database user, and the password of the same user. “localhost” can be replaced with the location of the database server.</li><li><strong>Stage III - Preparing the statement : </strong>Here, we prepare statements to be executed as SQL queries to the database. PreparedStatement or Statement class object can be used to prepare statements for execution.</li><li><strong>Stage IV - Executing the SQL statements : </strong>In this stage, the prepared statements are executed on the database. In the starting file, we are executing the statement for creating the table “employee”.</li></ul><p>For next stages, keep going!</p><p>Now, let’s implement the functionality to insert record into database. Write the following code into the “DbConstructor” class we just created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TUe613NiKZ8zJ_r7935V1g.png" /><figcaption>Functionality to insert record into database</figcaption></figure><p>Here, first we take all the required data (i.e. the id, name and salary) from the user. We will use the PreparedStatement class object to create executable statements. We insert the data entered by the user into the statement using the set functions(see line number 14, 15 and 16).</p><ul><li><strong>setString(position,&lt;String_data&gt;) :</strong> Sets the string data at the specified position (of the ‘?’ ) in the statement.</li><li><strong>setInt(position,&lt;Integer_data&gt;) :</strong> Sets the integer data at the specified position(of the ‘?’ ) in the statement.</li><li><strong>setFloat(position,&lt;Float_data&gt;) :</strong> Sets the string data at the specified position(of the ‘?’ ) in the statement.</li></ul><p><strong>executeUpdate() </strong>function<strong> </strong>executes the query and returns the number of rows affected by the query. If we run the code, we get the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8oxhq7NmLIRIK8a4ap2wCw.png" /><figcaption>Here, we’re inserting two records into the database.</figcaption></figure><p>Having inserted the records, how about fetching them out? Write the following code into the same class:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3WLBiOFvRS-ZuPHu5pD_A.png" /><figcaption>Functionality to retrieve data from database</figcaption></figure><p>As we have done earlier, we have prepared statement to get all records from the table “<strong>employee</strong>”. The result is stored in the ResultSet class object. <strong>next() </strong>function in ResultSet class is used to get the next row in the resultSet object. As you can see, we can access the data in the resultSet object by the get methods (quite similar to set methods), by providing the index position. Running the program gives the following output :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6lgxeRr4DIWsIBsnFER3g.png" /><figcaption>Records fetched from database</figcaption></figure><p>This is the 5^th stage in JDBC, i.e. processing the ResultSet .</p><p>Now, let’s write the functionality to update the record. In the DbConnector class :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pm0zq8igLkeIUmLT2qsYFw.png" /><figcaption>Functionality to update records in database</figcaption></figure><p>Here, we’re just accepting the data from user. Now I assume that you would be familiar with preparing query statements. Executing the code, you would get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NkfMrpYCxMd8aosmdWBMcA.png" /><figcaption>Here, we updated the record, and fetched them back to reflect the changes</figcaption></figure><p>Till here, we’ve inserted, fetched and updated the records in the database. Now, let’s move on to deleting records from database. In your DbConnector class, continue with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BTFuA6cvSXXC94FcA0BO5Q.png" /><figcaption>Functionality to delete record from database</figcaption></figure><p>All the code written here should be understandable to you by now! Executing the code produces the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NAeV2Knk8x8dPuoEYriW0g.png" /><figcaption>Output after deleting record, and fetching all records</figcaption></figure><p>The 6^th and the last step in JDBC is closing the database connection using the <strong>connection.close() </strong>method of the connection class. This method should be called after performing all the operations. Please note, this stage is not shown in this program!</p><p>Okay, did you see it? We have now successfully implemented the CRUD operations on database! Congrats! Note that this is not a very practical example of database connectivity with Java, it should be helpful to get you started. Hope it helps! Good luck!</p><p><em>Here’s the complete file for you:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i_IFeya6_JCM-hTJ6F8sbw.png" /><figcaption>Entire JdbcDemo.java file</figcaption></figure><blockquote>Please note, to see the output of individual functions, comment out the other functions &amp; run the program for that individual function!</blockquote><p><em>In the next part, we will be connecting our Java program with NoSQL database!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9866c4fb2d46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a basic REST API with Node.js from scratch!]]></title>
            <link>https://medium.com/swlh/creating-a-basic-rest-api-with-node-js-from-scratch-b8f539682452?source=rss-f270e797b6ad------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8f539682452</guid>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Mujawar Faiyaz Aziz]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 15:55:11 GMT</pubDate>
            <atom:updated>2020-06-14T15:26:16.653Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-NwaBKfvMMk1sXmNFSwYEg.png" /></figure><p>If you are trying to dive into the world of web development, then it’s quite sure that you would have came across the phrase “<strong>REST API”</strong>. There’s a lot of buzz around the term and everyone seems to be talking about the API and all that stuff. And if you have been thinking what that stuff it is, then you might be in the right place! Because today, we’re going to discuss the same.</p><p>This is gonna be a beginner-friendly blog, meant for the people having no prior experience with Node.js.</p><h3>What is REST API?</h3><p>First, let us start by describing what REST actually is. REST stands for <strong>RE</strong>presentational <strong>S</strong>tate <strong>T</strong>ransfer. And the API stands for <strong>A</strong>pplication <strong>P</strong>rogram Interface. Wait, what did I just say?! Don’t worry guys! However heavy the terms might sound, it’s actually quite simple! REST is nothing but software architecture design that is used for creating the web services. Most commonly used with HTTP requests, REST API, i.e the web service, provides resources, like files or data in JSON or XML format, to the clients requesting it.</p><p>REST APIs work with HTTP Verbs( GET , POST , PUT , PATCH &amp; DELETE )</p><h3>Defining HTTP Verbs:</h3><p>GET: As name suggests, this is used to get resource from web.</p><p>POST: This is used to add new resources to the web service.</p><p>PUT/PATCH: This is used to update any resource already present on the web service.</p><p>DELETE : This is used to delete any web resource from the web service.</p><h3>What are we building?</h3><p>We will be building a very simple REST API for a blogging site to demonstrate the CRUD(Create, Read, Update, Delete) operations. Our API will return the data in JSON format, as it is simpler to work with. We will be sending our requests to our API through <a href="https://www.postman.com/">Postman</a> .</p><h3>How do I do it?</h3><p>Having described what a REST API is, let’s move forward to creating it! In this tutorial, we’re gonna build the API on Node.js. We will be using Node.js with the express.js javascript library to build a basic REST API. So, let’s get going</p><p>Before proceeding any further, make sure you have properly installed Node.js on your system. If not, you can download and install it from <a href="https://nodejs.org/en/download/">here</a>.</p><p>First, open terminal and type the following commands:</p><pre>mkdir rest-api<br>cd rest-api</pre><p>This creates a folder named ‘rest-api’, which we would be using as our project folder.</p><p>Then type the following command:</p><pre>npm init -y</pre><p>npm — node-package-manager — comes bundled with Node.js and is used to install packages from the <a href="https://www.npmjs.com/">npm registry</a>.. This command creates a package.json file that lists all the npm packages installed.</p><p>Open the folder in any code editor of your choice. I would be using Visual Studio Code.</p><p>For creating the REST API, we will be needing a few npm packages.Run the following commands to install the required packages:</p><pre>npm install express mongoose<br>npm install -D nodemon</pre><p>When building REST API with Node.js, express.js is like the <em>de facto </em>library to go to. Also, ‘mongoose’ is the library used for our API to interact with the MongoDB database. Nodemon is used to re-run our API automatically everytime changes are made into the code, which would otherwise had to be done manually everytime. You may wish to read more about <a href="https://mongoosejs.com/">mongoose</a> and <a href="https://expressjs.com/">express</a> here.</p><p>So,let’s begin with the interesting part? Create a file named ‘index.js’ and write the following code into it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lb4dO8jXqgixj7psmj35Pw.png" /><figcaption>index.js — skeleton of our server</figcaption></figure><p>Here, we have just imported the express and mongoose library, and created an instance of server. The server is then started on port 3000.</p><p>To run the server i.e our API, run the command:</p><pre>nodemon index.js</pre><p>This gives the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXfztrj2ikMb6SM2dJ3IzQ.png" /></figure><p>Now let’s give some functionality to our bare-bone server. Create a folder named ‘models’, and into that folder, create a file named ‘Post.js’. Write the following code into it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EP1hoBg6G5QtPxUMXnIXSg.png" /><figcaption>Post.js — The structure of data to be stored</figcaption></figure><p>Once we have finalized the database schema, we are now ready to create the routes for our API. In the index.js file, write the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yq8HRKYMmVIdMsTycyvMhA.png" /><figcaption>functionality to get all posts stored in the database</figcaption></figure><p>Here, we have defined the ‘route’ to get all the posts stored in our database. ‘Route’ is the URL that you would type in the search bar of a browser. This route handles a <strong>GET</strong> request. On getting request on this route, our API will search the database and fetch all the post stored in there, and return them all in JSON format:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QurQUyQsulsOmYyIUhjm6g.png" /><figcaption>As currently we don’t have any post stored, we get an empty array as a result</figcaption></figure><p>Express.js provides convenient methods for handling the HTTP requests(namely get(),post(),put(),patch() and delete()). These methods have two parameters: a string representing the route, and a function to execute when a request is received. This function, in JavaScript world, is called as <strong>Callback Function</strong>. It has two parameters: first parameter represents the request object, and the second representing the the response object.</p><p>Done with reading all the posts? Now let’s put some of our posts in there! Write the following code in index.js file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkKliYWAjz5fEGSg_bPAGQ.png" /><figcaption>functionality to add post in the database</figcaption></figure><p>What we’re doing here is just defining another route to save a post. This route handles a <strong>POST</strong> request. We send the post details in JSON format to the API. The API extracts all the information as stores it in the database as a ‘post’, and return the response as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aZd90aesIApj4I4D3JwNKA.png" /><figcaption>Response received when post was saved successfully</figcaption></figure><p>If we now request our server to fetch all the posts, it would respond us with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kc4ZG2J2YQsVQGwQrBgYBg.png" /><figcaption>Response with all the posts</figcaption></figure><p>Now let’s move ahead with our API. Next, we write a route to get a specific post based on the post-ID we specify,i.e handling a <strong>GET </strong>request. In index.js, continue with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nTx3mrem-2rDbTuDTeui4A.png" /><figcaption>functionality to get post with specified ID</figcaption></figure><p>When a request hits our API at this route, it goes to the database, looks through all the posts and returns the post that has the same ID as provided. The response is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAWHuN8J6vWZZw2LCaDErw.png" /><figcaption>Response received with the requested Post</figcaption></figure><p>If no post with the specified post is found, the server will responds with:</p><pre>{<br>   &quot;msg&quot; : &quot;No post found&quot;<br>}</pre><p>Now, let’s define a route to update the post details! The API, on getting a request on this route will find the post with specified ID, and then updates the post title with the new one. If you have paid attention, this is the handling of <strong>PUT</strong> request! In your index.js file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_7gzwVX5l8RjpXfVBVS1Q.png" /><figcaption>functionality to update post details</figcaption></figure><p>Hitting the API with this route will result in the following response</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h5f_udECXPRWif2KdqvIzQ.png" /><figcaption>Title is updated</figcaption></figure><p>Having posted our thoughts, what if we wished to delete our post? Currently there’s no way to tell our API to remove any post. Never mind! We are programmers. We can fix that! Write the following code in your index.js file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-nCrl5wzvgeo7a6VafmFA.png" /><figcaption>functionality to delete post with specified ID</figcaption></figure><p>On receiving a request here, our API searches the database and deletes any post that has the ID as we provided. Pretty easy, huh ?! This handles the <strong>DELETE </strong>request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_AdWH_QzXk_nhFyeGYYbaA.png" /><figcaption>Response received when requested post gets deleted</figcaption></figure><p>Ahem, guess what? Hereby we have successfully created our first REST API!! You have successfully implemented the basic CRUD operations through an API, which is the basis of all web services development. Feeling great, yeah ?!</p><p>Here’s the complete index.js file for you to go through:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDhrniRYj1udNpq1PvOqlQ.png" /><figcaption>index.js — complete file</figcaption></figure><p>Young devs! This surely not the most complete introduction to REST APIs. But I think it’s good enough to get you all started. This is just the first stepping stone. Ahead there’s a hell lot more to learn. Hope you are prepared for it. And, Good Luck!</p><blockquote>Please give a clap if you find it helpful! It gives a me kick! 😁</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8f539682452" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/creating-a-basic-rest-api-with-node-js-from-scratch-b8f539682452">Creating a basic REST API with Node.js from scratch!</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>