Advanced Java and Web Technologies for JNTUK
Blog providing beginner tutorials on different web technologies like HTML, CSS, Javascript, PHP, MYSQL, XML, Java Beans, Servlets, JSP and AJAX

02/06/2015 Categories: JDBC. 2 Comments on Connecting to and Displaying data from MYSQL in XAMPP

This article explains about how to connect to a MYSQL database provided by XAMPP using Servlet and JDBC.


Following are assumed to be already installed and working on your system:

  • Linux or Windows operating system
  • Eclipse IDE


This tutorial assumes that the user has previous experience in working with MYSQL DBMS or using phpmyadmin and knowledge of writing programs in Java using JDBC. Now let’s start with the actual process.


Open XAMPP’s homepage by typing the URL: http://localhost/


Click phpmyadmin link available in the left-hand side menu. Default username for MYSQL database is root and password is empty. By default a database will be available by the name test.


Create a table named users with two columns name and pass. Insert some dummy data into the table.


Next step is to download the MYSQL’s ConnectorJ driver (jar file) available here. Next, add the mysql-connector-java-3.1.14-bin.jar file to the lib folder available in the WEB-INF folder of the project in Eclipse.


Now, insert the following Java code in a servlet file:



Run the above servlet to see the data from the users table on the webpage.

The entire project in WAR format is available for download here.

Related Links:

Popular Posts:

Note: Do you have a question on this article or have a suggestion to make this article better? You can ask or suggest us by filling in the below form. After commenting, your comment will be held for moderation and will be published in 24-48 hrs.


You can follow any responses to this entry through the RSS 2.0 feed.

How to connect if I am running it on eclipse using tomcat and the mysql xamp is on link like
I am using ubuntu and I have mysqlserver insatalled so, localhost get connceted to the local mysql server.

At line 27 in the above code, replace “localhost” with your mysql IP address. In this case it is “”

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll Up