To connect Java application with the MySQL database, we need to follow below following steps.
In this example we are using phpmyadmin as the database. So we need to know following informations for the mysql database:
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/GSSSKHOKHAR 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 GSSSKHOKHAR is the database name.
3) Username: The default username for the mysql database is root.
4) Password: It is the password given by the user at the time of installing the mysql database. In this example, we are going to use root as the password.
Let's first create a table in the mysql database, Table name : Students
LoginSystem.java
To connect java application with the mysql database, mysqlconnector.jar file is required to be loaded.
download the jar file mysql-connector.jar
Two ways to load the jar file:
1) Paste the mysqlconnector.jar file in jre/lib/ext folder2) Set classpath
Output : Login Screen
Output : Wrong Authentication - Login Screen
Output : Successfully - Login Screen
No comments:
Post a Comment