JSP connection with MYSQL in Linux

Now Let us  see how to connect jsp (Java Server Page) with Mysql in Linux - Ubuntu, mint, debian,. Java server page is a technology used to create dynamic web pages & server-side scripting language. It is similar to php but uses java programming language.

To run a jsp we need a web server,
   1.  Install  tomcat server in your system :
            by giving the following command in terminal

                          sudo apt-get install tomcat7      
          You can install a new version(version-8 ) of tomcat by specifying the version number in the  command.
          To test whether tomcat installed properly
         Open your browser & type the following URL:


             You will get the following result

  Install JDBC Driver :
                  To make a connection between JSP & Mysql, install a JDBC(connector/J) driver .
                                         link to Download
                          Extract the zip and get the mysql-connector-java-5.1.13-bin.jar file
                          Copy the .jar file to  the following location
      Restart the tomcat server :
                           sudo /etc/init.d/tomcat7 start
                                          sudo /etc/init.d/tomcat7 stop

    Apache tomcat server can be restarted by using following single cmd also.
                                          sudo /etc/init.d/tomcat6 restart 

         Now Let us create a Sample JSP with Mysql connection.  

<%@ page import="java.sql.*" %>
<%@ page import="*" %>

<title>Techie Touch | Mysql connectivity</title>
<h1>Connection status </h1>
try {
String connectionURL = "jdbc:mysql://localhost:3306/Database_name";
Connection connection = null;
// Load JBBC driver "com.mysql.jdbc.Driver"
/* user name = root
password =ur mysql password. */
connection = DriverManager.getConnection(connectionURL, "root", "password");
<font size="+3" color="green"></b>
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
catch(Exception ex){
<font size="+3" color="red"></b>
out.println("Unable to connect to database.");
<p>For more details..<a href="">Visit</a></p>

        ★  Save the file as test.jsp in the following path 
        ★   Now open the browser & run the above file by giving the following URL:

                            *****     Like us in FB & get updates ...... LIKE      ****



Post a Comment