Font Awesome Icons


Connectivity with MySQL

For connecting java application with the mysql database, you need to follow 5 steps to perform database connectivity:

1)Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver.

2)Connection URL: The connection URL for the mysql database is jdbc:mysql://localhost:3306/alok where jdbc is the API, mysql is the database, localhost is the server name on which mysql is running, we may also use IP address, 3306 is the port number and alok is the database name.

3)Username: The default username for the mysql database is root.

4)Password: Password is given by the user at the time of installing the mysql database. In this example, we are going to use root as the password.

Example to Connect Java Application with mysql database:

import java.sql.*; 

class MysqlCon

public static void main(String args[])




Connection con=DriverManager.getConnection( 



//here alok is database name, root is username and password

 Statement stmt=con.createStatement(); 


ResultSet rs=stmt.executeQuery(“select * from emp”); 



System.out.println(rs.getInt(1)+”  “+rs.getString(2)+”  “+rs.getString(3)); 





catch(Exception e)





Hi, Welcome to etechvidya