• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Java » Servlet

MySql LocalTime() function in Java Servlet

By Dinesh Thakur

This Function will tell Local Time.

First i make a table in database named ‘dbase’ with required fields and values which is under the reference of mySql(php myAdmin). Here I import all mandatory java packages from the java library as program needs. Then after, I make a class named ‘MySqlLocalTime’ extends ‘HttpServlet’. And here I use serviceMethod() which will get request from the doGet()Method for getting output on the web browser. After, I load all the required drivers for accessing database. After, then i declare mandatory variables as i declare ‘Connection’ this variable does the job to create a link between database and the actual code. The other one i declare is ‘resultSet’ that will fetch the value from selected column and rows. Now here i declare the ‘preparedStatement’ that will use to execute the selected query like executeQuery() as (Select LOCALTIME() AS now). Here i use the doGet()Method for output on a web browser.

While on the web browser to being output in tabular form I use ‘HTML’ code and tags for a manner way look.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLocalTime extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select LOCALTIME() AS now");
                  rs = ps.executeQuery();
               String title = "Using Local Time Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Local Time</th>\n"+ "</body> </html>");
                 while(rs.next())
                   {
                       String curr = rs.getString(1);
                    disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                   }     
            }         
                    catch(Exception e) 
                        {
                         e.printStackTrace();
                        }
                         disp.close();
      }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                            doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLocalTime</servlet-name>
   <servlet-class>MySqlLocalTime</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLocalTime</servlet-name>
   <url-pattern>/MySqlLocalTime</url-pattern>
</servlet-mapping>

MySql LN Function in Java Servlet

By Dinesh Thakur

Will Return Log value of selected number.

First, I make a table in database named ‘dbase’ within the reference of mySql(php myAdmin). Then i import all the mandatory java packages from the java library as required for program. I made a class named ‘MySqlLNFunction’, which extends ‘HttpServlet’. I use serviceMethod() which is been carry the request from doGet()Method for Output. Then before, declaring the variable i loaded all the required drivers before for database accessing. Here i declare the variables like ‘connection’ this variable will create a link between database and java code. Then, i call ‘resultSet’ this will be responsible for Getting value from the selected columns and the rows. Then i declare ‘preparedStatement’ which will get to execute the selected query like executeQuery() as (Select LN(5)).here i use doGet()Method which will use to get output on the web browser.

While getting Output on the Web Browser we use ‘HTML’ Code or some of these tags to present Output in tabular form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLNFunction extends HttpServlet
 {
        public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
           {
                rp.setContentType("text/html");
                PrintWriter disp = rp.getWriter();
                String driver = "com.mysql.jdbc.Driver";
                String url = "jdbc:mysql://localhost/dbase";
                String uid = "root";
                String psw = "root";
                Connection con=null;
                PreparedStatement ps = null;
                ResultSet rs;
                try
                 {
                       Class.forName(driver);
                       con = DriverManager.getConnection(url,uid,psw);
                       ps=con.prepareStatement("Select LN(5)");
                       rs = ps.executeQuery();
                    String title = "Using LN(LOGRITHM) Function";
                      String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                    disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                       "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                     "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                      while(rs.next())
                          {
                               String val = rs.getString(1);
                            disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                          }     
               }      
                            catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
            }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                                     doGet(rq,rp);
                           }
  }
 
WEB.xml
 
<servlet>
   <servlet-name>MySqlLNFunction</servlet-name>
   <servlet-class>MySqlLNFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLNFunction</servlet-name>
   <url-pattern>/MySqlLNFunction</url-pattern>
</servlet-mapping>

MySql Literal Characters in Java Servlet

By Dinesh Thakur

This Function Will Add The Two Strings.

First, we have To Make a Table Named ‘worker’ In MySql (Php MyAdmin) Into the Database Named ‘dbase’. Then we have to call The Packages from java Library. Then We Make a Class Named ‘MySqlLiteralCharacters’ Extends “HttpServlet”. After, Initializing The Class We Declare The Methods Public void Service(),(The service method call the doGet() method for GET request from User) and In That The Objects called “Response Object” and “Request Object Which will Work According To Work. After, that We have to Load the Driver and Make Variables Of Resultset,Connection to establish The link between database and Query that Execute The Condition after Calling. After, Declaring the Prepared statement we have to put the Query (“SELECT last_name ||’ is a ‘||job_id as UC FROM worker”). After that We will Use executeQuery() Method to Extract the Result On a Web Browser.

On the web Browser I use ‘Html’ tags to print the output in tabular form on the web browser this will present output in a manner Form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLiteralCharacters extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
              {
                    Class.forName(driver);
                    con = DriverManager.getConnection(url,uid,psw);
                    ps=con.prepareStatement("SELECT last_name ||' is a '||job_id as UC FROM worker");
                    rs = ps.executeQuery();
                 String title = "Using of Literal Characters";
                   String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                   "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +"</body> </html>");
                  while(rs.next())
                      {
                           String l_name = rs.getString("UC");
                         String  j_id = rs.getString("UC");
                           disp.println("<tr><td align=\"center\">" + l_name +  "<td align=\"center\">" + j_id +"</td></tr>" );  
                      }     
            }         
                         catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
        }
                          public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                {
                                     doGet(rq,rp);
                                }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLiteralCharacters</servlet-name>
   <servlet-class>MySqlLiteralCharacters</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLiteralCharacters</servlet-name>
   <url-pattern>/MySqlLiteralCharacters</url-pattern>
</servlet-mapping>

MySql LENGTH Function in Java Servlet

By Dinesh Thakur

This Function will return the length of a string in bytes.

First i made a database named ‘dbase’ within the reference of mySql(php myAdmin) with required fields and values in it. Then according to need of program, I import all the java packages from the java library. I create a class named ‘MySqlLENGTHFunction’, which extends ‘HttpServlet’. Then, i use serviceMethod() that will bring the request from doGet()Method for output on web browser. After, using serviceMethod() i loaded all the required Drivers mandatory for database accessing. Here after, i declare variables as first i use ‘connection’ this will use to create a link between database and the java code. Then i use ‘resultSet’ this use to get the value from selected columns and rows. And the other one i use is ‘preparedStatement’ this will use to executing the selected Query like executeQuery() as (Select LENGTH(‘MySql’)).I use doGet()Method for output on the web browser.

Now to get the output on the web browser in an impressive look I use ‘HTML’ code and some of these tags, which will bring output in the tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLENGTHFunction extends HttpServlet
 {
       public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
         {
              rp.setContentType("text/html");
              PrintWriter disp = rp.getWriter();
              String driver = "com.mysql.jdbc.Driver";
              String url = "jdbc:mysql://localhost/dbase";
              String uid = "root";
              String psw = "root";
              Connection con=null;
              PreparedStatement ps = null;
              ResultSet rs;
              try
                {
                    Class.forName(driver);
                    con = DriverManager.getConnection(url,uid,psw);
                    ps=con.prepareStatement("Select LENGTH('MySql') as lnth");
                    rs = ps.executeQuery();
                 String title = "Using LENGTH Function";
                   String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                 disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                    "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                 "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                   while(rs.next())
                       {
                             String val = rs.getString(1);
                          disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                       }     
             }        
                          catch(Exception e) 
                              {
                                    e.printStackTrace();
                              }
                                    disp.close();
      }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                               doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLENGTHFunction</servlet-name>
   <servlet-class>MySqlLENGTHFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLENGTHFunction</servlet-name>
   <url-pattern>/MySqlLENGTHFunction</url-pattern>
</servlet-mapping>

MySql LTRIM Function in Java Servlet

By Dinesh Thakur

This Function will remove leading spaces.

First I made a database named ‘dbase’ within the reference of mySql(php myAdmin). Then after, i import all java packages from java library as program need. Here I made a class named ‘MySqlLEFTRIMFunction’, which extends ‘HttpServlet’. I use service()Method that will help to getting the request from doGet()Method for output on web browser. Then, i loaded all the required Drivers that will help to accessing Database. After then, i declare variable first i use ‘connection’ variable that will create a link between database and the actual code (frontEnd and the backEnd). Other variable is ‘ResultSet’ that will help to fetch value from the columns and rows as required query. The next variable is ‘preparedStatement’ that will use to executing the selected Query like executeQuery as (Select LTRIM(‘  JavaMySql’).I use doGet()Method in last instance that will bring the output on web browser.

To get output on the web browser i use ‘HTML’ code and tags that will present the output in a tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLEFTRIMFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
               {
                     Class.forName(driver);
                     con = DriverManager.getConnection(url,uid,psw);
                     ps=con.prepareStatement("Select LTRIM('  JavaMySql') as ltrm");
                     rs = ps.executeQuery();
                  String title = "Using LTrim Function";
                    String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                  disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                  "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                     while(rs.next())
                       {
                             String val = rs.getString(1);
                          disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                       }     
             }        
                          catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
       }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                             doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLEFTRIMFunction</servlet-name>
   <servlet-class>MySqlLEFTRIMFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLEFTRIMFunction</servlet-name>
   <url-pattern>/MySqlLEFTRIMFunction</url-pattern>
</servlet-mapping>

MySql LPAD Function in Java Servlet

By Dinesh Thakur

This Function will return the string argument, left-padded with the specified string.

First of all i made a database named ‘dbase’ within the reference of mySql(php myAdmin).Here i also import required java packages from java library. Then after i made a class named ‘MySqlLEFTPADFunction’ which extends ‘HttpServlet’. Then i use service()Method that will bring request from the doGet()Method for output. Just before declaring variable i loaded all the required drivers that are necessary for database accessing. Then after i use variable like i use ‘connection’ for creating a link between database and java code. Other i use ‘resultSet’ that will do the required job to fetch value from the selected columns and rows. Other one is ‘preparedStatement’ that will use to executing the selected Query like executeQuery() as (Select LPAD(‘MySql’,5,’!!’). In the last phase i use doGet()Method that will present output on the web browser.

Now i used some kind of ‘HTML’ code and tags that will present the output in a tabular form on a web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLEFTPADFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select LPAD('MySql',5,'!!') as lpad");
                  rs = ps.executeQuery();
               String title = "Using LEFTPAD Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                 "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                while(rs.next())
                  {
                       String val = rs.getString(1);
                    disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                  }     
             }        
                    catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
       }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                             doGet(rq,rp);
                           }
 }
 
WEB.xml
 
<servlet>
   <servlet-name>MySqlLEFTPADFunction</servlet-name>
   <servlet-class>MySqlLEFTPADFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLEFTPADFunction</servlet-name>
   <url-pattern>/MySqlLEFTPADFunction</url-pattern>
</servlet-mapping>

MySql LeftCase Function in Java Servlet

By Dinesh Thakur

This Function Will Return the leftmost number of characters as specified.

First i made a table with required fields and values in that into a database named ‘dbase’ with the reference of mySql(php Myadmin). Then i import all the required packages from java library. Then i made a class named ‘MySqlLeftCaseFunction’ extends the ‘HttpServlet’.then i use serviceMethod() which will use to getting request from the doGet()Method for Output. Then i load all the required Drivers. Then, i declare some mandatory variables like connection (Connection variable is been used to make a bridge or link between database and actual code (java code)). As after creating link between both platforms, i declare resultSet, which will be use to fetch the values from required fields according to user. The other one variable is preparedStatement the object of this variable is ‘ps’ this will use to execute the query like executeQuery() as(Select LEFT(‘MySqlJava’,’5′)). To in the end i use doGet()Method for getting value on the web Browser.

On the web Browser i use ‘Html’ tags to print the output in tabular form on the web browser this will present output in a manner Form. 

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLeftCaseFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
              {
                   Class.forName(driver);
                   con = DriverManager.getConnection(url,uid,psw);
                   ps=con.prepareStatement("Select LEFT('MySqlJava','5') as lft");
                   rs = ps.executeQuery();
                String title = "Using LeftCase Function";
                  String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                  while(rs.next())
                   {
                        String val = rs.getString(1);
                     disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                   }     
              }       
                     catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
     }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                             doGet(rq,rp);
                           }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLeftCaseFunction</servlet-name>
   <servlet-class>MySqlLeftCaseFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLeftCaseFunction</servlet-name>
   <url-pattern>/MySqlLeftCaseFunction</url-pattern>
</servlet-mapping>

MySql LastDay Function in Java Servlet

By Dinesh Thakur

This Function Will show the Last Day of Month

First i make a table in database named ‘dbase’ within the reference of mySql(php myAdmin).then i import all the required java packages from the java library.then i made a class named ‘MySqlLastDayFunc’ which extends ‘HttpServlet’. then after i use service()Mehod which will get the request from the doGet()Method.then i loaded all the require drivers for the database accessing.herei declare the variables like ‘connection’ this varaible will take over to create a link beetween a database and the java code.the other i declare ‘resultSet’ this will use to fetch the value from the columns and the rows from selected table.then i declare the ‘preparedStatement’ this variable will execute the selected query like executeQuery() as (Select LAST_DAY(‘2014-05-31’)).i here use doGet()Method that will bring the output on the web browser.

To Getting Output on web browser in a tabular form i use ‘HTML’ code and tags.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlLastDayFunc extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
             {
                 Class.forName(driver);
                 con = DriverManager.getConnection(url,uid,psw);
                 ps=con.prepareStatement("Select LAST_DAY('2014-05-31') AS ld");
                 rs = ps.executeQuery();
              String title = "Using Last Day Function";
                String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                 "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Last Day Was</th>\n"+ "</body> </html>");
                 while(rs.next())
                     {
                          String curr = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                     }     
            }         
                      catch(Exception e) 
                               {
                                   e.printStackTrace();
                               }
                                   disp.close();
       }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                                     doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlLastDayFunc</servlet-name>
   <servlet-class>MySqlLastDayFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlLastDayFunc</servlet-name>
   <url-pattern>/MySqlLastDayFunc</url-pattern>
</servlet-mapping>

MySql IS OPERATOR Function in Java Servlet

By Dinesh Thakur

This Function will return that the given value is True or false.

The first i make a table in database named ‘dbase’ with the required fields and value in it, database is been created within the reference of mySql(php myAdmin). Then i import all the required java packages from java library according to the program need. I made a class named ‘MySqlISOPERATORFunction’ completely extends ‘HttpServlet’. Then i use the serviceMethod() which use to getting request from doGet()Method. Here i loaded all the required drivers for database accessing. After that, i declare mandatory variables for database conditions. Like i declare ‘Connection’ this variable will use to create a link between database and the java code. The other one will be the ‘resultSet’ this will be the responsible for the fetching value from the selected columns and rows. The next variable will be the ‘preparedStatement’ this variable is been used to executing the selected query like executeQuery() as (SELECT 9 IS TRUE).now here i use doGet()method which will bring the output on web browser.

Now i used some kind of ‘HTML’ code and tags that will present the output in a tabular form on a web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlISOPERATORFunction extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                   Class.forName(driver);
                   con = DriverManager.getConnection(url,uid,psw);
                   ps=con.prepareStatement("SELECT 9 IS TRUE");
                   rs = ps.executeQuery();
                String title = "Using IS OPERATOR Function";
                  String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                   "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                  while(rs.next())
                      {
                           String val = rs.getString(1);
                        disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                      }      
             }        
                        catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
     }
                         public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                                     doGet(rq,rp);
                           }
  }
Web.xml
 
<servlet>
   <servlet-name>MySqlISOPERATORFunction</servlet-name>
   <servlet-class>MySqlISOPERATORFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlISOPERATORFunction</servlet-name>
   <url-pattern>/MySqlISOPERATORFunction</url-pattern>
</servlet-mapping>

MySql ISNULL Function in Java Servlet

By Dinesh Thakur

This Function will Test a Null Value.

First we need to make a table with required fields into a database named ‘dbase’ within the reference of MySql(Php MyAdmin).first we need to import all the require packages from the java library. Then we will make a class named ‘MySqlISNULLFunction’ which extends ‘HttpServlet’. After then we define serviceMethod() which will bring the request from doGet()method for Output. Then we need to declare all the required Drivers for Database linking. Next move will be to declare mandatory variables for accessing the database like Connection variable this variable will make a bridge or link between database and actual code within the help of drivers. The next variable will be the resultSet this will be use to fetch value from the required columns and rows. And the preparedStatement will does the job as it will use to execute the Query like executeQuery() as (SELECT 2 IS NULL). And in the end the whole criteria goes to doGet()method which will help to getting output on the web browser.

i Use ‘HTML’ code and some tags which will show the output in tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlISNULLFunction extends HttpServlet
   {
        public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
          {
              rp.setContentType("text/html");
              PrintWriter disp = rp.getWriter();
              String driver = "com.mysql.jdbc.Driver";
              String url = "jdbc:mysql://localhost/dbase";
              String uid = "root";
              String psw = "root";
              Connection con=null;
              PreparedStatement ps = null;
              ResultSet rs;
              try
                {
                     Class.forName(driver);
                     con = DriverManager.getConnection(url,uid,psw);
                     ps=con.prepareStatement("SELECT 2 IS NULL");
                     rs = ps.executeQuery();
                  String title = "Using IS NULL() Function";
                    String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                  disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                  "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                    while(rs.next())
                        {
                             String val = rs.getString(1);
                          disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                        }     
             }        
                          catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
      }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                             doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlISNULLFunction</servlet-name>
   <servlet-class>MySqlISNULLFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlISNULLFunction</servlet-name>
   <url-pattern>/MySqlISNULLFunction</url-pattern>
</servlet-mapping>

MySql ISNOT Function in Java Servlet

By Dinesh Thakur

This Function will Test a value against a Boolean.

First we need to make a table with required fields into a database named ‘dbase’ within the reference of MySql(Php MyAdmin).First we need to import all the required packages from the java library. Then we will make a class named ‘MySqlISNOTFunction’, which extends ‘HttpServlet’. After then, we define serviceMethod() which will bring the request from doGet()method for Output. Then, we need to declare all the required Drivers for Database linking. Next move will be to declare mandatory variables for accessing the database like Connection variable this variable will make a bridge or link between database and actual code within the help of drivers. The next variable will be the resultSet this will be use to fetch value from the required columns and rows. And the preparedStatement will does the job as it will use to execute the Query like executeQuery() as (SELECT 2 IS NOT UNKNOWN). And in the end the whole criteria goes to doGet()method which will help to getting output on the web browser.

On to the web browser we need to use ‘HTML’ code and its tags to get Output in Tabular form or in a manner way.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlISNOTFunction extends HttpServlet
   {
       public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
               {
                     Class.forName(driver);
                     con = DriverManager.getConnection(url,uid,psw);
                     ps=con.prepareStatement("SELECT 2 IS NOT UNKNOWN");
                     rs = ps.executeQuery();
                   String title = "Using IS NOT Function";
                     String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                   disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                   "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                     while(rs.next())
                        {
                                String val = rs.getString(1);
                             disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                        }      
             }        
                             catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
        }
                             public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                  {
                                     doGet(rq,rp);
                                  }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlISNOTFunction</servlet-name>
   <servlet-class>MySqlISNOTFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlISNOTFunction</servlet-name>
   <url-pattern>/MySqlISNOTFunction</url-pattern>
</servlet-mapping>

MySql INTERVAL Function in Java Servlet

By Dinesh Thakur

This function will Takes multiple expressions and returns 0 if exp 1 is less than exp 2.

First I made a table with required fields and values in that into a database named ‘dbase’ with the reference of mySql(php Myadmin). Then i import all the required packages from java library. Then i made a class named ‘MySqlINTERVALFunction’ extends the ‘HttpServlet’. Then i use serviceMethod() which will use to getting request from the doGet()Method for Output. Then load all the required Drivers. Then i declare some mandatory variables like connection (Connection variable is been used to make a bridge or link between database and actual code (java code)). As after creating link between both platforms, I declare resultSet, which will be using to fetch the values from required fields according to user. The other one variable is preparedStatement the object of this variable is ‘ps’ this will use to execute the query like executeQuery() as(SELECT INTERVAL(95, 45, 23, 1, 93,86, 275)). To in the end i use doGet()Method for getting value on the web Browser.

For getting value in a manner form, I use ‘HTML’ code tags, which will present the Output on the Web Browser in a tabular form.  

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlINTERVALFunction extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("SELECT INTERVAL(95, 45, 23, 1, 93,86, 275)");
                  rs = ps.executeQuery();
               String title = "Using INTERVAL Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
               while(rs.next())
                   {
                        String val = rs.getString(1);
                     disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                   }     
            }         
                     catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
    }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                                     doGet(rq,rp);
                           }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlINTERVALFunction</servlet-name>
   <servlet-class>MySqlINTERVALFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlINTERVALFunction</servlet-name>
   <url-pattern>/MySqlINTERVALFunction</url-pattern>
</servlet-mapping>

MySql INSTRING Function in Java Servlet

By Dinesh Thakur

This function will return the index of the first occurrence of substring.

First I make a table in database named ‘dbase’ with required fields and values in it and within the reference of mySql(Php Admin). Then I import the required java package from java library. I made a class named ‘MySqlINSTRINGFunction’ extends the ‘HttpServlet’. Then i use serviceMethod() which will bring the request from doGet()Method for Output. Then I load all the drivers for database accessing. After then i declare variables which are necessary for database conditions like i declare connection(this variable will use to make a link between database and java code or actual code).after then i declare resultset (this variable will use to get the values from desired columns and rows as required from query).the next one will be the preparedStatement (this variable will responsible for the executing query like executeQuery() as (Select INSTR(‘MySQL’,’SQL’)). In the last i used the doget()Method which will bring the output on the web Browser.

On the web Browser for getting output in the manner form, I used ‘HTML’ tags, which will present the output in a tabular form on a web browser.

import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlINSTRINGFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
            {
                 Class.forName(driver);
                 con = DriverManager.getConnection(url,uid,psw);
                 ps=con.prepareStatement("Select INSTR('MySQL','SQL') as instr");
                 rs = ps.executeQuery();
              String title = "Using INSTRING Function";
                String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
             disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
             "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
               while(rs.next())
                  {
                       String val = rs.getString(1);
                    disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                  }     
           }          
                    catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
     }
                       public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                              doGet(rq,rp);
                           }
  }
WEB.XML
<servlet>
   <servlet-name>MySqlINSTRINGFunction</servlet-name>
   <servlet-class>MySqlINSTRINGFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlINSTRINGFunction</servlet-name>
   <url-pattern>/MySqlINSTRINGFunction</url-pattern>
</servlet-mapping>

MySql INSERT Function in Java Servlet

By Dinesh Thakur

This function will insert a substring at the specified position up to the specified number of characters.

We have created database named ‘dbase’. After that a class is been declared named ‘MySqlINSERTFunction’ extends the ‘HttpServlet’. With that kind of efforts, we need to define some methods, which do their job for producing output. After we just declare Service method () (service method does the job of calling doGet() method for getting request). Some variables also define as Connection,Resultset,PreparedStatement. Connection variable use to create link between database and actual code (Frontend and Backend). PreparedStatement will use to send the query to database like (Select INSERT(‘MySQL’,3,0,’Java’)). This statement will work according to condition it shows. Now the next method executeQuery() will execute desired query and statement. And in the end doGet() method will be used to fetch the result on a web browser.

To feel look good the result we use a tabular form concept. For this kind of requirement, we use ‘HTML’ coding and some of tags to use Output in Designer look to show on a web browser. 

import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlINSERTFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
            {
                Class.forName(driver);
                con = DriverManager.getConnection(url,uid,psw);
                ps=con.prepareStatement("Select INSERT('MySQL',3,0,'Java') as ins");
                rs = ps.executeQuery();
             String title = "Using INSERT Function";
               String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
             disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
             "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
               while(rs.next())
                   {
                       String val = rs.getString(1);
                     disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                   }     
            }         
                     catch(Exception e) 
                         {
                          e.printStackTrace();
                         }
                          disp.close();
    }
                            public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                 {
                                     doGet(rq,rp);
                                 }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlINSERTFunction</servlet-name>
   <servlet-class>MySqlINSERTFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlINSERTFunction</servlet-name>
   <url-pattern>/MySqlINSERTFunction</url-pattern>
</servlet-mapping>

MySql IN Function in Java Servlet

By Dinesh Thakur

This function will use to check that required Value is in the expression or Not.

I made a database named ‘dbase’ that made in the reference of mySql(php myAdmin). After I import all the required java packages from java library. Then I made a class named ‘MySqlINFunction’ which extends ‘HttpServlet’. Then i use service()Method that will help to get the request from the doGet()Method for output. After i loaded all the required drivers for database accessing. I declare variables as I use ‘connection’ that will use to make a link with database and the java code. The other i declare is ‘resultSet’ that will responsible for the getting value from the selected columns and the rows. Then i use ‘preparedStatement’ that will be using to executing the selected Query like executeQuery() as (SELECT 8 IN(2,8,7)). I use here in last phase doGet()Method that will present the value on the web browser.

I use here ‘Html’ code and tags that will present the output in tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlINFunction extends HttpServlet
 {
   public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
     {
        rp.setContentType("text/html");
        PrintWriter disp = rp.getWriter();
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost/dbase";
        String uid = "root";
        String psw = "root";
        Connection con=null;
        PreparedStatement ps = null;
        ResultSet rs;
        try
         {
             Class.forName(driver);
             con = DriverManager.getConnection(url,uid,psw);
             ps=con.prepareStatement("SELECT 8 IN(2,8,7)");
             rs = ps.executeQuery();
            String title = "Using IN() Function";
            String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
            disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
            "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
            "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
            while(rs.next())
                {
                     String val = rs.getString(1);
                  disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                }     
         }
                  catch(Exception e) 
                       {
                        e.printStackTrace();
                     }
                        disp.close();
       }
                          public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                           {
                            doGet(rq,rp);
                           }
  }
WEB.xml
 
<servlet>
   <servlet-name>MySqlINFunction</servlet-name>
   <servlet-class>MySqlINFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlINFunction</servlet-name>
   <url-pattern>/MySqlINFunction</url-pattern>
</servlet-mapping>

MySql Hour Function in Java Servlet

By Dinesh Thakur

The function ‘HOUR’ will show the current Hour of system.

I make a table in database named ‘dbase’ with required fields and within the reference of mySql(php myAdmin). Then i import all the required java packages from java library. Then i made class which extends ‘HttpServlet’ named ‘MySqlHourFunc’. I use here serviceMethod() that will use to getting the request from the doGet ()method. Before declaring desired variables i loaded all the required drivers for database accessing. Then After I declare variable like ‘connection’ that will make a link between the database and the actual code. Here i declare ‘resultSet’ Also which is been responsible for the fetching value from the columns and rows. I declare ‘preparedStatement’ that will use to executing selected query like executeQuery() as (Select HOUR(now()))).I use doGet()Method that will get Output on the web browser.

While getting the output on the web browser i use ‘HTML’ code and tags that present output in tabular form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlHourFunc extends HttpServlet
 {
    public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
            {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select HOUR(now()) AS hr");
                  rs = ps.executeQuery();
               String title = "Using HOUR Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                 "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Result</th>\n"+ "</body> </html>");
                while(rs.next())
                     {
                           String curr = rs.getString(1);
                        disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                     }     
            }         
                        catch(Exception e) 
                              {
                                 e.printStackTrace();
                              }
                                 disp.close();
      }
                                   public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                       {
                                         doGet(rq,rp);
                                       }
 }
 
WEB.xml
 
<servlet>
   <servlet-name>MySqlHourFunc</servlet-name>
   <servlet-class>MySqlHourFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlHourFunc</servlet-name>
   <url-pattern>/MySqlHourFunc</url-pattern>
</servlet-mapping>

MySql HEXA Function in Java Servlet Example

By Dinesh Thakur

This Function will return the HEXA DECIMAL value of a number.

First i made a database named ‘dbase’ within the reference of mySql(php myAdmin). Then I import all the required java packages from java library as program essentials. I made a class named ‘MySqlHEXAFunc’, which extends ‘HttpServlet’. Then i use service()Method which will use to get the request from the doGet()Method for output on the browser. i loaded all the required drivers for accessing database as required. Then i use to declare the variable as I use ‘connection’ this will use to create a link between the database and the java code. Then i declare ‘resultSet’ this will responsible for get the value from selected columns and the rows. i use here now ‘preparedStatement’ this will execute the selected Query like executeQuery as (Select HEX(378)). Then i use doGet()Method that will bring the output on the web browser.

I use here some tags of ‘HTML’ that will bring output in a tabular form as required.  

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlHEXAFunc extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
              {
                   Class.forName(driver);
                   con = DriverManager.getConnection(url,uid,psw);
                   ps=con.prepareStatement("Select HEX(378)");
                   rs = ps.executeQuery();
                String title = "Using HEXA Function";
                  String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                  while(rs.next())
                     {
                          String val = rs.getString(1);
                        disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                     }     
              }       
                        catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
      }
                                     public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                      {
                                         doGet(rq,rp);
                                      }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlHEXAFunc</servlet-name>
   <servlet-class>MySqlHEXAFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlHEXAFunc</servlet-name>
   <url-pattern>/MySqlHEXAFunc</url-pattern>
</servlet-mapping>

MySql GREATER THAN Function in Java Servlet

By Dinesh Thakur

This function will return the value that greater from other number or expression.

I made a database first named ‘dbase’ within the reference of mySql(php myAdmin). Then i import all required java packages from java library. Then i made a class named ‘MySqlGREATERTHANFunction’ that extends the ‘HttpServlet’. I use here service()Method that will bring the request from doGet()method for an output. Then i loaded all the required drivers from database accessing. Here i use to declare some variables as i use ‘connection’ this will create a link between the database and the java code. The other variable i used to ‘resultSet’ this will get the value from the desired columns and the rows as well. In the last phase i use ‘preparedStatement’ that will responsible for executing Selected Query like executeQuery() as (SELECT 8 > 2). I use doGet() method that will use to get result on the web browser.

Now here i use to set ‘Html’ Code and tags that will present the output in tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlGREATERTHANFunction extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
              {
                     Class.forName(driver);
                     con = DriverManager.getConnection(url,uid,psw);
                     ps=con.prepareStatement("SELECT 8 > 2");
                     rs = ps.executeQuery();
                  String title = "Using GREATER THAN Function";
                    String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                  disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                  "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                    while(rs.next())
                       {
                            String val = rs.getString(1);
                         disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                       }     
              }       
                         catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
    }
                                    public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                     {
                                       doGet(rq,rp);
                                     }
  }
WEB.xml
<servlet>
   <servlet-name>MySqlGREATERTHANFunction</servlet-name>
   <servlet-class>MySqlGREATERTHANFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlGREATERTHANFunction</servlet-name>
   <url-pattern>/MySqlGREATERTHANFunction</url-pattern>
</servlet-mapping>  

MySql GREATER Function in Java Servlet

By Dinesh Thakur

This function will show that the greater Number Between Two expressions.

Then i made a database named ‘dbase’ within the reference of mySql(php myAdmin). Here i call or import all the required java packages from java library. That after i made a class named ‘MySqlGREATERFunction’ extends ‘HttpServlet’. I use here serviceMethod() that is responsible for the getting request from doGet()Method for output on the web browser. Here after i loaded all the required drivers for database accessing. Then after i need to be declare variables i use first ‘connection’ this variable is responsible for the creating a link between the database and the actual code. The second one i declare ‘resultSet’ this will use to get value from the selected columns and the rows as well. The next one i declare is to ‘preparedStatement’ this will be act as to executing the selected query like executeQuery() as (SELECT GREATEST(2,8)). In the last phase of coding i use doGet()Method that will be responsible for the output on web browser.

To getting output in tabular form i use some tags from ‘HTML’ that bring the result as desired on web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlGREATERFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
             {
                 Class.forName(driver);
                 con = DriverManager.getConnection(url,uid,psw);
                 ps=con.prepareStatement("SELECT GREATEST(2,8)");
                 rs = ps.executeQuery();
              String title = "Using GREATEST Function";
                String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
             disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
             "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
               while(rs.next())
                   {
                        String val = rs.getString(1);
                     disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                   }     
             }        
                     catch(Exception e) 
                        {
                            e.printStackTrace();
                        }
                            disp.close();
       }
                              public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                  {
                                     doGet(rq,rp);
                                  }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlGREATERFunction</servlet-name>
   <servlet-class>MySqlGREATERFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlGREATERFunction</servlet-name>
   <url-pattern>/MySqlGREATERFunction</url-pattern>
</servlet-mapping>

MySql GREATER EQUAL TO Function in Java Servlet

By Dinesh Thakur

This function will show that the expression is greater equal or not with other expression.

Then i made a database named ‘dbase’ within the reference of mySql(php myAdmin). Here i call or import all the required java packages from java library. That after i made a class named ‘MySqlGREATEREQUALTOFunction’ extends ‘HttpServlet’. I use here serviceMethod() that is responsible for the getting request from doGet()Method for output on the web browser. Here after i loaded all the required drivers for database accessing. Then after i need to be declare variables i use first ‘connection’ this variable is responsible for the creating a link between the database and the actual code. The second one i declare ‘resultSet’ this will use to get value from the selected columns and the rows as well. The next one i declare is to ‘preparedStatement’ this will be act as to executing the selected query like executeQuery() as (SELECT 2 >= 2). In the last phase of coding i use doGet()Method that will be responsible for the output on web browser.

Here i use some ‘HTML’ tags for getting output in tabular form that bring it in a manner way on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlGREATEREQUALTOFunction extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
               {
                    Class.forName(driver);
                    con = DriverManager.getConnection(url,uid,psw);
                    ps=con.prepareStatement("SELECT 2 >= 2");
                    rs = ps.executeQuery();
                 String title = "Using GREATER EQUAL TO Function";
                   String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                 disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                    "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                 "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                   while(rs.next())
                        {
                             String val = rs.getString(1);
                          disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                        }     
               }      
                          catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
     }
                                      public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                         {
                                           doGet(rq,rp);
                                         }
 }
Web.xml
 
<servlet>
   <servlet-name>MySqlGREATEREQUALTOFunction</servlet-name>
   <servlet-class>MySqlGREATEREQUALTOFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlGREATEREQUALTOFunction</servlet-name>
   <url-pattern>/MySqlGREATEREQUALTOFunction</url-pattern>
</servlet-mapping>

MySql Get_Format() in Java Servlet

By Dinesh Thakur

This function will use to get the desired Date Format.

First i made a table in database named ‘dbase’ within the reference of mySql(php myAdmin). Then after i import all the java packages from java library. I made a class named ‘MySqlGetFormat’ which extends ‘HttpServlet’. I use here the method service()Method that will use to getting the request from the doGet()Method for an output on the web browser. I loaded all the required drivers for accessing the database. I use here variables as required as I use ‘connection’ this variable will create a link between the database and the java code. This variable named ‘resultSet’ will use to get the value from the selected columns and rows from the selected table as required. After that i use to declare ‘preparedStatement’ that will use to executing the Selected query like executeQuery as (Select GET_FORMAT(DATE,’EUR’)). I use doGet()Method for getting output on the web browser.

On the web browser, I use to set ‘HTML’ code and those tags that will Bring output in tabular form on browser. 

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlGetFormat extends HttpServlet
 {
       public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
         {
               rp.setContentType("text/html");
               PrintWriter disp = rp.getWriter();
               String driver = "com.mysql.jdbc.Driver";
               String url = "jdbc:mysql://localhost/dbase";
               String uid = "root";
               String psw = "root";
               Connection con=null;
               PreparedStatement ps = null;
               ResultSet rs;
               try
                {
                     Class.forName(driver);
                     con = DriverManager.getConnection(url,uid,psw);
                     ps=con.prepareStatement("Select GET_FORMAT(DATE,'EUR') AS gf");
                     rs = ps.executeQuery();
                  String title = "Using Get Format Function";
                    String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                  disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                  "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Required Result</th>\n"+ "</body> </html>");
                    while(rs.next())
                          {
                                String curr = rs.getString(1);
                             disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                          }     
             }        
                             catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
     }
                                    public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                      {
                                         doGet(rq,rp);
 }
Web.xml
 
<servlet>
   <servlet-name>MySqlGetFormat</servlet-name>
   <servlet-class>MySqlGetFormat</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlGetFormat</servlet-name>
   <url-pattern>/MySqlGetFormat</url-pattern>
</servlet-mapping>

MySql FromDays in Java Servlet

By Dinesh Thakur

This Function will Converts a day number to a Date.

Then i use to make a database named ‘dbase’ that is been built in the reference of mySql(php ,yAdmin). Then i import all the required java packages from java library. Then i made a class named ‘MySqlFromDays’, which extends ‘HttpServlet’. Then i use service()Method that will use to getting the request from doGet()Method for output on the web browser. Then i loaded all the required drivers for the database accessing. Then i declare mandatory variables i use ‘connection’ this variable will use to create a link between database and the java code. Then i use ‘resultSet’ that return the value from selected columns and rows from table as required. Other i declare ‘preparedStatement’ that will use to executing the selected query like executeQuery() as (Select FROM_DAYS((365*2014)). I use doGet()Method for output on the web browser.

To get output on the web browser i use ‘HTML’ code and tags which present it in tabular form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlFromDays extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select FROM_DAYS((365*2014)) AS st");
                  rs = ps.executeQuery();
               String title = "Using From_Days Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                 "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Start Of 2014</th>\n"+ "</body> </html>");
                 while(rs.next())
                     {
                           String curr = rs.getString(1);
                        disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                     }     
              }       
                        catch(Exception e) 
                              {
                                   e.printStackTrace();
                              }
                                   disp.close();
       }
                                     public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                      {
                                         doGet(rq,rp);
                                      }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlFromDays</servlet-name>
   <servlet-class>MySqlFromDays</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlFromDays</servlet-name>
   <url-pattern>/MySqlFromDays</url-pattern>
</servlet-mapping>

MySql FORMAT Functon in Java Servlet

By Dinesh Thakur

This function will provide the formatted value of expression with decimal place.

I use to made a database first named ‘dbase’ within the reference of mySql(php myAdmin). Then i import all important java packages from java library. Then i made a class named ‘MySqlFORMATFunc’ extends ‘HttpServlet’. Then i use service()Method this will be responsible for the getting the request from the doGet()Method for output. Then i loaded all the required drivers for the database accessing. Then i use to set variables like i use first variable ‘connection’ that will be responsible for the creating a link between database and the java code. Then i use ‘resultSet’ this will use to get value from the selected columns and the rows from table. I use here ‘preparedStatement’ that use to executing the selected query like executeQuery() as (Select FORMAT(12378.8787,8)). Then in last phase i use doGet()Method that will provide the output on the web browser.

I use ‘HTML’ code and tags to show output in tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlFORMATFunc extends HttpServlet
   {
       public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
         {
               rp.setContentType("text/html");
               PrintWriter disp = rp.getWriter();
               String driver = "com.mysql.jdbc.Driver";
               String url = "jdbc:mysql://localhost/dbase";
               String uid = "root";
               String psw = "root";
               Connection con=null;
               PreparedStatement ps = null;
               ResultSet rs;
               try
                {
                      Class.forName(driver);
                      con = DriverManager.getConnection(url,uid,psw);
                      ps=con.prepareStatement("Select FORMAT(12378.8787,8)");
                      rs = ps.executeQuery();
                   String title = "Using Format Function";
                     String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
                  disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                     "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
                  "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                    while(rs.next())
                        {
                             String val = rs.getString(1);
                          disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                        }      
              }       
                          catch(Exception e) 
                              {
                                  e.printStackTrace();
                              }
                                  disp.close();
     }
                                    public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                       {
                                         doGet(rq,rp);
                                       }
 }
WEB.xml
 
<servlet>
   <servlet-name>MySqlFORMATFunc</servlet-name>
   <servlet-class>MySqlFORMATFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlFORMATFunc</servlet-name>
   <url-pattern>/MySqlFORMATFunc</url-pattern>
</servlet-mapping>

MySql FLOOR() Function in Java Servlet

By Dinesh Thakur

This Function will Returns the largest integer value that is not Greater than passed numeric expression.

First i made a database named ‘dbase’ within the reference of mySql(php myAdmin). Then i import all the required java package from java library according to  need of program. Then i made a class named ‘MySqlFLOORFunction’ which extends ‘HTTPSERVLET’ completely. Then after i use service()Method that will bring the request from doGet()Method for output on the web browser.

Then after i loaded al the required drivers for database accessing. Here i declare variables for next use of program i declare ‘connection’ that will use to create a link between the database and the java code. Here i use ‘resultSet’ that will use to get the value from the selected columns and the rows. At the last instance of declaring variable i use ‘preparedStatement’ that will use to executing the selected Query like executeQuery as (Select FLOOR(‘8.69’)). I use doGet()Method for output on web browser.

I use ‘HTML’ coding and some tags to present the output on the web browser in tabular form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlFLOORFunction extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
             {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select FLOOR('8.69')");
                  rs = ps.executeQuery();
               String title = "Using FLOOR Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                 "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                while(rs.next())
                     {
                          String val = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                     }     
             }        
                       catch(Exception e) 
                         {
                                e.printStackTrace();
                         }
                                disp.close();
      }
                                  public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                    {
                                       doGet(rq,rp);
                                    }
 }
Web.xml
 
<servlet>
   <servlet-name>MySqlFLOORFunction</servlet-name>
   <servlet-class>MySqlFLOORFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlFLOORFunction</servlet-name>
   <url-pattern>/MySqlFLOORFunction</url-pattern>
</servlet-mapping>

MySql FIELD Function in Java Servlet

By Dinesh Thakur

The Function ‘FIELD’ will return the position of the first argument.

In the first instance of programming i made a database named ‘dbase’ that within the reference of mySql(php myAdmin).Then i import all the required java packages from java library. Then i made a class named ‘MySqlFIELDFunc’ extends ‘HttpServlet’. I use here service()Method that will getting the request from doGet()Method for output on the web browser. I loaded all the required drivers for database accessing. Here i use variables for database link i use ‘connection’ this will create a link a between database and the java code. I use ‘resultSet’ this will use to get the value from the selected columns and the rows. Then i use ‘preparedStatement’ that will use to executing the query like executeQuery as (Select FIELD(‘my’,’call’,’my’,’hex’,’my’)). I use here doGet()Method for output on the web browser.

I use here ‘HTML’ code and some of these tags to present output in the tabular form on the web browser for manner way.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlFIELDFunc extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
            rp.setContentType("text/html");
            PrintWriter disp = rp.getWriter();
            String driver = "com.mysql.jdbc.Driver";
            String url = "jdbc:mysql://localhost/dbase";
            String uid = "root";
            String psw = "root";
            Connection con=null;
            PreparedStatement ps = null;
            ResultSet rs;
            try
              {
                   Class.forName(driver);
                   con = DriverManager.getConnection(url,uid,psw);
                   ps=con.prepareStatement("Select FIELD('my','call','my','hex','my')");
                   rs = ps.executeQuery();
                String title = "Using FIELD Function";
                  String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                 while(rs.next())
                    {
                          String val = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                    }     
              }       
                        catch(Exception e) 
                         {
                             e.printStackTrace();
                         }
                             disp.close();
     }
                               public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                  {
                                     doGet(rq,rp);
                                  }
}
Web.xml
 
<servlet>
   <servlet-name>MySqlFIELDFunc</servlet-name>
   <servlet-class>MySqlFIELDFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlFIELDFunc</servlet-name>
   <url-pattern>/MySqlFIELDFunc</url-pattern>
</servlet-mapping>

MySql Extract Function in Java Servlet

By Dinesh Thakur

This function will extract the Date.

Then first i made a database named ‘dbase’ within the reference of mySql(php myAdmin). After i import all required java packages from java library. Then i made a class named ‘MySqlExtractFunc’ which extends ‘HttpServlet’. After that i use service()Method that will bring the request from doGet()Method for output on the web browser. Then i loaded all the required drivers that are mandatory for database accessing. Then i use variable ‘connection’ that will use to create a link between the database and the java code. After i use ‘resultSet’ this variable will use to get the value from the columns and the rows. Then i use ‘preparedStatement’ that will use executing the selected Query like executeQuery as (Select EXTRACT(HOUR_MINUTE from NOW()).I use in the end doGet()Method that bring the output on the web browser.

I use some tags of ‘HTML’ that will bring the output in tabular form on the web browser.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlExtractFunc extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
             {
                 Class.forName(driver);
                 con = DriverManager.getConnection(url,uid,psw);
                 ps=con.prepareStatement("Select EXTRACT(HOUR_MINUTE from NOW()) AS ex");
                 rs = ps.executeQuery();
              String title = "Using Extract Function";
                String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
             disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Extract Example</th>\n"+ "</body> </html>");
                while(rs.next())
                   {
                          String curr = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + curr +"</td></tr>" );  
                   }     
             }        
                       catch(Exception e) 
                         {
                           e.printStackTrace();
                         }
                           disp.close();
    }
                             public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                  {
                                     doGet(rq,rp);
                                  }
}
Web.xml
 
<servlet>
   <servlet-name>MySqlExtractFunc</servlet-name>
   <servlet-class>MySqlExtractFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlExtractFunc</servlet-name>
   <url-pattern>/MySqlExtractFunc</url-pattern>
</servlet-mapping>

MySql EXPORT SET Function in Java Servlet

By Dinesh Thakur

The function ‘Export Set’ will return the string such that for every bit set in the value bits.

First i made a database named ‘dbase’ that within the reference of mySql(php myAdmin).that after i import all the required java packages from java library. Here now i made a class named ‘MySqlEXPORTSETFunc’ extends ‘HttpServlet’. Then after i declare service()Method that will get the request from the doGet()Method. Then before to declare variable I loaded all the required drivers for database accessing use first variable ‘connection’ this variable will responsible for the creating a link between the database and actual code. The next one will be ‘resultSet’ this will use to get the value from selected columns and rows. The next move to declare ‘preparedStatement’ this will executing the selected Query like executeQuery() as (Select EXPORT_SET(1,’M’,’Y’,’,’,’4′)). Here i use in last doGet()Method that will bring the output on web browser.

To get output in tabular form on the web browser i use ‘HTML’ code and some tags.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlEXPORTSETFunc extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
       {
           rp.setContentType("text/html");
           PrintWriter disp = rp.getWriter();
           String driver = "com.mysql.jdbc.Driver";
           String url = "jdbc:mysql://localhost/dbase";
           String uid = "root";
           String psw = "root";
           Connection con=null;
           PreparedStatement ps = null;
           ResultSet rs;
           try
             {
                 Class.forName(driver);
                 con = DriverManager.getConnection(url,uid,psw);
                 ps=con.prepareStatement("Select EXPORT_SET(1,'M','Y',',','4')");
                 rs = ps.executeQuery();
              String title = "Using EXPORT_SET Function";
                String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
              "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                while(rs.next())
                 {
                      String val = rs.getString(1);
                   disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );   
                 }     
             }        
                   catch(Exception e) 
                      {
                        e.printStackTrace();
                      }
                        disp.close();
     }
                          public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                              {
                                doGet(rq,rp);
                              }
}
Web.xml
 
<servlet>
   <servlet-name>MySqlEXPORTSETFunc</servlet-name>
   <servlet-class>MySqlEXPORTSETFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlEXPORTSETFunc</servlet-name>
   <url-pattern>/MySqlEXPORTSETFunc</url-pattern>
</servlet-mapping>

MySql EXP Function in Java Servlet

By Dinesh Thakur

This function will return the natural base of logarithm (e).

First i made a database named ‘dbase’ within the complete reference of mySql(php myAdmin).then i import all the required java package from java library as program need. Then after i made a class that is been extends the ‘HttpServlet’. Then i use to get request from doGet()method the serviceMethod() for output on web browser. Then i loaded all the mandatory drivers for database accessing. After then the next move is to declare variables like i use ‘connection’ this will use to make a bridge or link between database and the actual code(java code). After then i use ‘resultSet’ that will be responsible for the getting value from the selected columns and rows. Then i use ‘preparedStatement’ this will use to executing the selected query like executeQuery as (Select EXP(5)). In the last i use doGet() method that will bring the output on the web browser.

I use some tags of ‘HTML’ tags into coding for presenting output in tabular form on the web browser.

import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlEXPFunction extends HttpServlet
   {
       public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
         {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
               {
                   Class.forName(driver);
                   con = DriverManager.getConnection(url,uid,psw);
                   ps=con.prepareStatement("Select EXP(5)");
                   rs = ps.executeQuery();
                String title = "Using EXP Function";
                  String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
                 while(rs.next())
                    {
                         String val = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                    }     
               }      
                       catch(Exception e) 
                        {
                             e.printStackTrace();
                        }
                             disp.close();
     }
                                public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                   {
                                     doGet(rq,rp);
                                   }
 }
WEB.xml
<servlet>
   <servlet-name>MySqlEXPFunction</servlet-name>
   <servlet-class>MySqlEXPFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlEXPFunction</servlet-name>
   <url-pattern>/MySqlEXPFunction</url-pattern>
</servlet-mapping>

MySql EQUAL() Function in Java Servlet

By Dinesh Thakur

This function will show that the expression value’s are Equal or Not.

First of all i made a database named ‘dbase’ within the reference of mySql(php myAdmin).here i also import required java packages from java library. Then after i made a class named ‘MySqlEQUALFunction’ which extends ‘HttpServlet’. Then i use service()Method that will bring request from the doGet()Method for output. Just before declaring variable I loaded all the required drivers that are necessary for database accessing. Then after i use variable like i use ‘connection’ for creating a link between database and java code. Other i use ‘resultSet’ that will do the required job to fetch value from the selected columns and rows. Other one is ‘preparedStatement’ that will use to executing the selected Query like executeQuery() as (SELECT 1=2). In the last phase i use doGet()Method that will present output on the web browser.

I use ‘HTML’ code and some of these tags that will provide the output on the web browser in tabular form.

 import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlEQUALFunction extends HttpServlet
 {
     public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
      {
         rp.setContentType("text/html");
         PrintWriter disp = rp.getWriter();
         String driver = "com.mysql.jdbc.Driver";
         String url = "jdbc:mysql://localhost/dbase";
         String uid = "root";
         String psw = "root";
         Connection con=null;
         PreparedStatement ps = null;
         ResultSet rs;
         try
          {
              Class.forName(driver);
              con = DriverManager.getConnection(url,uid,psw);
              ps=con.prepareStatement("SELECT 1=2");
              rs = ps.executeQuery();
              String title = "Using EQUAL  Function";
              String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
              disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
              "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
            "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value</th>\n"+ "</body> </html>");
              while(rs.next())
                 {
                      String val = rs.getString(1);
                   disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                 }      
           }          
                   catch(Exception e) 
                       {
                         e.printStackTrace();
                       }
                         disp.close();
     }
                            public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                {
                                     doGet(rq,rp);
                                }
 }
Web.xml
 
<servlet>
   <servlet-name>MySqlEQUALFunction</servlet-name>
   <servlet-class>MySqlEQUALFunction</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlEQUALFunction</servlet-name>
   <url-pattern>/MySqlEQUALFunction</url-pattern>
</servlet-mapping>

MySql Elt Function in Java Servlet

By Dinesh Thakur

This function ‘ELT’ will return the String at index Number.

First i use to make a database named ‘dbase’ within the reference of mySql(php myAdmin). Then i use to import all required java package from java library. Then after calling all the packages i made a class named ‘MySqlEltFunc’ which extends ‘HttpServlet’. i use service()Method which will use to getting the request from doGet()Method for output. Then i loaded all the required drivers for database accessing. After loading driver i declare the variables like i use ‘connection’ variable that will use to create a link between the database and the java code. Then after i use ‘resultSet’ that will act as to fetching value from the selected column and rows. i use ‘preparedStatement’ that will use to executing the selected query like executeQuery() as (Select ELT(‘1′,’en’,’java’)). I use doGet()Method in last interface which will use to get output on the web browser.

Here I use ‘HTML’ code and tag that will represent the output in tabular form on the web browser.

import java.io.IOException; 
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MySqlEltFunc extends HttpServlet
 {
      public void service(HttpServletRequest rq, HttpServletResponse rp)throws IOException, ServletException
        {
             rp.setContentType("text/html");
             PrintWriter disp = rp.getWriter();
             String driver = "com.mysql.jdbc.Driver";
             String url = "jdbc:mysql://localhost/dbase";
             String uid = "root";
             String psw = "root";
             Connection con=null;
             PreparedStatement ps = null;
             ResultSet rs;
             try
              {
                  Class.forName(driver);
                  con = DriverManager.getConnection(url,uid,psw);
                  ps=con.prepareStatement("Select ELT('1','en','java')");
                  rs = ps.executeQuery();
               String title = "Using ELT Function";
                 String docType ="<!doctype html public \"-//w3c//dtd html 4.0 " + "transitional//en\">\n";
               disp.println(docType + "<html>\n" + "<head><title>" + title + "</title></head>\n" +
                  "<body bgcolor=\"#f4efef\">\n" + "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n" +
               "<table width=\"50%\" border=\"1\" align=\"center\">\n" + "<th>Value Is </th>\n"+ "</body> </html>");
                 while(rs.next())
                     {
                          String val = rs.getString(1);
                       disp.println("<tr><td align=\"center\">" + val +"</td></tr>" );  
                     }     
              }       
                       catch(Exception e) 
                         {
                             e.printStackTrace();
                         }
                             disp.close();
       }
                               public void doPost(HttpServletRequest rq,HttpServletResponse rp)throws IOException,ServletException
                                  {
                                     doGet(rq,rp);
                                  }
 }
Web.xml
 
<servlet>
   <servlet-name>MySqlEltFunc</servlet-name>
   <servlet-class>MySqlEltFunc</servlet-class>
</servlet>
<!-- servlet mapping -->
<servlet-mapping>
   <servlet-name>MySqlEltFunc</servlet-name>
   <url-pattern>/MySqlEltFunc</url-pattern>
</servlet-mapping>
« Previous Page
Next Page »

Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW