======================================================================================================== Java Program to show the database connectivity with JDBC Driver on Command Line Interface ======================================================================================================== We have to follow below steps: Driver class: The driver class for the mysql database is com.mysql.jdbc.Driver. Connection URL: The connection URL for the mysql database is jdbc:mysql://localhost:3306/YourDBName 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 YourDBName is the database name. We may use any database, in such case Username: root Password: root Download the mysqlconnector.jar file. Go to jre/lib/ext folder and paste the jar file here. Download Link: https://static.javatpoint.com/src/jdbc/mysql-connector.jar Set the classpath: C:\folder\mysql-connector-java-5.0.8-bin.jar;.; ======================================================================================================== Add This Theory part in your file ======================================================================================================== Create Table in DataBase: CREATE TABLE `studentinfo` ( `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `studentname` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, `college` varchar(100) NOT NULL, `rollno` varchar(100) NOT NULL, `password` varchar(100) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; ======================================================================================================== import java.sql.*; class DbConnectivity{ public static void main(String args[]){ try{ Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/student","root",""); //here student is database name, root is username and password Statement stmt=con.createStatement(); ResultSet rs=stmt.executeQuery("select * from studentinfo"); while(rs.next()) System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4)+" "+rs.getString(5)); con.close(); }catch(Exception e){ System.out.println(e);} } }