How to connect Java application with MySQL using NetBeans

This article will teach you how to connect Java application with MySQL database using NetBeans. Connecting your Java application in NetBeans with MySQL is not a difficult task.

How to connect Java application with MySQL using NetBeans

This article will teach you how to connect Java application with MySQL database using NetBeans. Connecting your Java application in NetBeans with MySQL is not a difficult task.

Requirements

Downloading MySQL JDBC driver

  • To download the latest version of the JDBC driver, visit this link. From Select Operating System drop-down, select Platform Independent and download the zip archive.
  • Extract and open the downloaded file. There will be a file named mysql-connector-java-8.0.12.jar (version number may be different).

Setting-up database

  • Start xampp.
  • Turn on Apache and Mysql.
  • Create a MySQL database.

Configuring the NetBeans project

  • Open NetBeans and create a new project by clicking File->New Project.
  • From the Choose Project window, select Java->Java Application and click next.
  • Choose a project name and click Finish.
  • Expand the project folder and Right-click on Libraries.
  • Select Add JAR/Folder.
  • Select mysql-connector-java-8.0.12.jar and click open. Now you will see the jar file listed under Libraries.
  • Go to Window->Services.
  • Right-click on Databases and select New Connection.
  • Click Add and select mysql-connector-java-8.0.12.jar file. From Driver drop-down, select MySQL (Connector/J driver). Click Next.
  • In the Customize Connection window, replace the Database name with the one you have created for the application. If you have not created a database, leave it as it is.
  • Click Test Connection.

If you get a Connection Succeeded message, you have connected your application with the MySQL database.


Share Tweet Send
0 Comments
Loading...