Ad Code

Responsive Advertisement

Initialize MySQL Connection in Java

In my past tutorial "Java to MySQL Database Connection", we already discussed the code and the functions for connecting to MySQL.

This tutorial will teach you on how to initialize the MySQL connection. It means that when you open a JFrame or jInternalFrame in java, the MySQL connection will initialized. When the program access the database without any problem, the JFrame/JInternalFrame will display but if not, the program will display an error on establishing MySQL Connection.

Image: KnowledgeWala


Required Libraries

  1. MySQL JDBC Driver

To do this, you need to find the public method of your class. In Netbeans is very simple, the public method always call/display initComponents() method. In my case, I have a class named "Inventory" and to initialize the connection I inserted "conn = dbconnection.db_config();" statement. The second sets of codes are the imports. We used imports to access the required libraries for MySQL.

Post a Comment

0 Comments

Close Menu