Showing posts with label Web. Show all posts
Showing posts with label Web. Show all posts

Access MySQL from Android through RESTful Web Service

Finally, I found some time to write about accessing MySQL or any database that you can think about from an Android application. Android offers a built-in database known as SQLite which is supposed to be used for local data storage. For example, if you want to store your recent transactions locally in the device, you have to go with SQLite. I have already written a few articles on how to use SQLite database in Android. However, enterprise mobile applications often depend on client/server databases such as MySQL, Oracle DB or MongoDB. Whatever the database, you have chosen, the way to access them from an Android application is pretty same. In this article, I explain how to access a MySQL database from an Android application written in Kotlin.

I will use Kotlin for all upcoming Android tutorials because it is the future of Android programming. Kotlin is a JVM based language and you can easily convert a Kotlin project into Java and vice versa.

An Android application is not supposed to directly access a database deployed in a server. I do not recommend implementing JDBC connections in an Android application due to the tight coupling introduced between the application and the database. The industrial best practice requires you to implement a web service between the database and the Android application. Having a web service layer reduces the complexity of the Android application and also reduces the dependency on database specific operations. Therefore, the problem of accessing a client/server database like MySQL from an Android application can be defined as the problem of consuming a web service hosted somewhere.

Having said that, as an Android developer, you don't need to care about what is behind the web service. It may be a MySQL database, MongoDB database, a Social Media network or even a Weather Network API. What you need is the API endpoints exposed by the web service. In this article, I only explain how to connect to a web service hosted on your local machine from an Android application. However, the sample web service used in this article provides API endpoints to CRUD operations on a MySQL database. Please follow the RESTful CRUD With Java and MySQL in Minutes article and develop the web service to access a MySQL database. In the following section, you will learn how to access the web service you have created for accessing a database.
Read More

Apache Axis2 - Hello World! using Eclipse

The previous article Apache Axis2 - Hello World! provides step by step guide to develop a very basic Axis2 Hello World application without using any IDEs. This article helps you to create a simple application in Axis2 using Eclipse IDE.

Prerequisite:
  • Eclipse IDE for Java EE Developers (Follow this link to install Eclipse)
  • Apache Tomcat (Follow this link to install and integrate with Eclipse)
  • Apache Axis2 (Follow this link to install and integrate with Eclipse)

Update (01/05/2017): With the Axis2 library 1.7.4 there are some JSTL related errors in the JSP file. If you get such errors in your project, add the jstl-1.2.jar into the WebContent/lib directories.

Step 1:
Create a new Dynamic Web Project named HelloAxis2 and change the Dynamic web module version to 2.5 because the current version of Axis2 core does not support versions higher than 2.5.


Read More
Apache Axis2 - Hello World!

Apache Axis2 - Hello World!

Apache Axis2 is a SOAP processing engine and its main function is to deliver incoming SOAP messages into target applications, and in this context application is a Web service. This tutorial provides step by step guidance on how to create your first Hello World application.

Prerequisite:
  • Java Development Kit (Follow this link to install on Ubuntu)
  • Apache Axis2 (Follow this link to setup on Ubuntu)

Step 1:
Create a new class HelloService as shown below.
public class HelloService {

    /**
    * This method will be the add operation of the web service.
    */
    public int add(int x, int y) {
        int ans = x + y;
        return ans;
    }

}


Read More

Jersey 2.x - Hello, world!

The first tutorial about Jersey: Jersey 1.x - Hello, world! shows the way to develop a simple RESTful Web service application using Jersey 1.19. This tutorial shows you the way to develop the same application using Jersey 2.20. Eclipse for Java EE developers and Apache Tomcat are used to develop the application. If you do not have them, please setup them before continuing this tutorial.

For Ubuntu users:
For any users:
Integrate Tomcat with Eclipse
Read More

Jersey 1.x - Hello, world!

Developing RESTful Web services that seamlessly support exposing your data in a variety of representation media types and abstract away the low-level details of the client-server communication is not an easy task without a good toolkit. In order to simplify development of RESTful Web services and their clients in Java, a standard and portable JAX-RS API has been designed. Jersey RESTful Web Services framework is open source, production quality, framework for developing RESTful Web Services in Java that provides support for JAX-RS APIs and serves as a JAX-RS (JSR 311 & JSR 339) Reference Implementation.

This tutorial shows how to develop a simple hello world RESTful application using Jersey 1.19. This tutorial uses Eclipse for Java EE developers and Apache Tomcat as the development tools. If you do not have them, please setup them before continuing this tutorial.

For Ubuntu users:
For any users:
Integrate Tomcat with Eclipse

Step 1:
Create a new “Dynamic Web Project” in Eclipse, by New → Project → Dynamic Web Project.


Read More

Stripes - Hello, World!

Stripes is an open source web application framework used to simplify Java web development. Stripes provides both View and Controllers of MVC architecture and let the developers port their Model into the system. Comparing to Struts, Stripes is a lightweight and less configuration needed framework, but it provides almost everything provided by Struts. More details about Stripes can be found here.

This tutorial shows you; how to develop a simple web application using Stripes framework in Eclipse.

Prerequisite:
  • Java Development Kit 1.5 or latest
  • Eclipse JEE
  • Apache Tomcat (To add Apache Tomcat to Eclipse, follow this link.)
  • Stripes libraries and other dependencies
  • Basic knowledge in Java Servlets and JSP.
Create a new Dynamic Web Project
Step 1:
In Eclipse goto File → New → Project… and select Dynamic Web Project


Read More

Introduction to Servers

This article mainly focuses the developers who wants to get the Oracle Certified Expert, Java EE 6 Web Component Developer (OCEWCD 6 - 1Z0-899) certification. In this article you will get a brief introduction of web servers, application servers and Servlet containers.

I noticed in my classes; there were some students, even do not know what kind of web development they are going to learn. They thought the OCEWCD is all about HTML, JavaScript and CSS, so this article starts with an introduction to client side applications and server side applications. There are two components in a web application. We call them as server side application and client side application. If you take an application, the fancy stuffs you see in your web browser belong to the client side. The background business logic, database access, session management and even more functional requirements are handled by server side component. Client side developers mostly use HTML, JavaScript, CSS, etc to develop the application. They are the artists and they know the way to attract the users. On the other hand, server side developers use languages like Java, Perl or PHP where the main concern is serving to the client side application and providing the functional requirements. OCEWCD exam is for the server side application developers, even though there are some client side JSP related topics.



Read More

Contact Form

Name

Email *

Message *