connect JSP with mysql in Linux

Let us make a simple application to connect and access mysql database from jsp code. This covers example jsp program to connect mysql, installing apache tomcat server, configuring mysql connector to establish jdbc driver, setting up the connection. 1st application using jsp.

To run a java server page in localhost, we need to setup a server.

Installing Latest Apache Tomcat server :

Run the following command in the terminal,

                         sudo apt-get install tomcat8            

Find all occurrence of character in the string

Program to find index of particular character occur throughout the string.

Index tell where the character occur.

void Findindex(char c,int n)


int n=0;

int result;

String str=”roses”;








invoking the method


output of the above program:




Know how the indexOf method is used in java.

indexOf() method in java

Java string indexOf() with example program and explanation.

indexOf(char c)

It return index of first occurrence of a character in the string.


String str="tet";

int result= str.indexOf('e');

Now, the value of result will be 1.

indexOf(char c, int fromindex)

Fromindex set the index from where the particular character is to be searched.


Given a string of odd length, return length three from its middle- replaceALL

java replaceAll() method with example program. This kind of question are asked in codingbat. Improve your programming skills by solving this, its for beginners. Program with explanation.

public String middleThree(String str)


String newstr;

int mid;

str=str.replaceAll(“\\s” , “”);

int len=str.length();



return str;




return newstr;


Below program explain java replace() method. Syntax, example and explanation.

Replace particular character with other in a String JAVA

simple java program to replace particular character in a string with other.

class replaceProgram{
    public static void main(String args[])  {

String st1=”TechieTet”;
String st2=st1.replace(‘e’,’x’);

Output of this program will be

  Txchix Txt


Syntax of replace method

    replace(char oldchar, char newchar)

   replace(string oldstr, string newstr)

Not only character also a part of string i.e substring can be changed using replace.

Reverse the string Program in java

Simple program to reverse the string in java. This logic, also used to check whether the given string is palindrome or not. By comparing string after reversing it.

class reverseProgram {
    public static void main(String args[])  {

String reverse=” “;
String original=”Techie Tet”;
int len=original.length();
for(int i=len-1;i>=0;i--)



Factorial using recursion program

Simple java program for factorial using recursion with explanation. Easy logic, can be used in C#(sharp), python, php, perl... etc.

int fact(int n)
int result;
return 1;
return result;

Understand the logic behind recursion, so you don’t feel factorial using recursion as difficult.

Input -5, Output – 120.


How to find factorial of number 5 using recursion.

Recursion – Function call itself.

Example 1: