Java Servlets

Servlet technology is used to create web application (stays at server side and generates a dynamic web page).

Servlet technology is robust and scalable because of java language. Before Servlet, CGI (Common Gateway Interface) scripting language was common as a server-side programming language. However, there were many disadvantages to this technology. We have discussed these disadvantages below.

There are many interfaces and classes in the Servlet API such as Servlet, GenericServlet, HttpServlet, ServletRequest, ServletResponse, etc.

Software Required:

  1. Java JDK. (Version 7 or Above)
  2. Tomcat Apache Server (7.0 is preferred).

Check the below video for setup of

Java Servlet Execution and Enviromnet Setup for Windows Base OS.

Above video is demonstrated for the purpose of learning and education of B.C.A. and BSC.IT. Students of Saurashtra University.

JDBC with MySQL

JDBC stands for Java Database Connectivity is quite a way that helps Java Users to interact with many versatile Database. I am going to show you the connectivity for JDBC with MySQL because both are Open Source in terms of using it.

Software Requried:

  • Java JDK.
  • Xampp or any other application that let’s you interact with phpmyadmin to create a database.
  • MySQL Connector for JDBC Connectivity.

Steps for JDBC setup

  • Download and Install Xampp or Laragon.
  • Download MySQL Connector and follow below steps.
  • Extract the file.
  • Paste the mysqlconnector.jar [Your Drive]\Java\jdk[version]\jre\lib\ext
  • Right Click on mysqlconnector.jar and GOTO properties.
  • In Properties Look for Unblock Button, If not found than go for Coding.

Note: [Your Data] Square Brackets are your Environment Setup.

Source Code:

imort java.sql.*;
class JDBCEX {
    Connection con;
    Statement st;
    ResultSet rs;
    public JDBCEX() { //Constructor
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/[YourDatabase]"); 
            //There should be a database named as test in your phpmyadmin.
            System.out.println("Connected Successfully");
            st = con.createStatement();
            rs = st.executeQuery("Select * from [YourTable]"); 
            //There should be a table named as test1 in your database test1.
            while (rs.next()) {
              //Keep Some records in table to run this code.
              System.out.println("RNO : " + rs.getInt(1) + "\nNAME : " + rs.getString(2) + "\nAddress : " + rs.getString(3) + "\nEmail : " + rs.getString(4) + "\n");
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    public static void main(String args[]) {
        JDBCEX test = new JDBCEX();
    }
}
JDBC MySQL Integration