How to connect to the MySQL database in NetBeans

Source: Internet
Author: User
Tags mysql command line netbeans

We often use associated databases when building Java Desktop applications through NetBeans. Therefore, this article will introduce how to create a MySQL database connection from NetBeans.

Before connecting, install the following software:

(1) NetBeans 6.5

(2) JDK 6 (Update 13)

(3) MySQL 5

You can install NetBeans after installing JDK, and then install MySQL. Remember the port number (usually 3306 by default) and database password when installing MySQL. Next, I will introduce in detail how to connect to the MySQL database in NetBeans. This document uses the database named cars as an example.

1. Start the MySQL command line client, enter the database Password, Run "create database cars;" to create a database named cars, and run "show databases;" to check whether the database is created successfully. As follows:

2. Start NetBeans 6.5, click "service", select "Database", right-click and create a connection. The following window is displayed, as shown in. the specific port and database password will be related to the settings when MySQL is installed. The MySQL port here adopts the default 3306, and the database password is set to 33123. click OK.

3. Click "OK" to check that the connection is successful, as shown in:

4. After the database connection is established, right-click "jdbc: mysql: // localhost: 3306/cars" and choose "Run Command" to write and execute the SQL script, the preceding SQL script is used to create a table named car in the cars database. The table contains multiple attributes, such as the car brand (make) and model (size, and contains many fields ). After the script is imported, run the script language.

As shown in:

5. Click "jdbc: mysql: // localhost: 3306/cars". You can see that a table named car has been created in the cars database, as shown in:

6. In NetBeans, click "file", select "New Project", select "java", and select "java Desktop Application", for example:

7. Click "Next" on Step 6 and select "database application", as shown in:

8. Click "Next" on top of Step 7. In "database connection", select a connection established in step 3 and select the attribute to be displayed, click "Next", as shown in the following two figures:

 

9. After completing the above eight steps, you can run the main project, as shown in:

You can also add, delete, and perform other operations.

In addition, you can add the Swing control to further improve the functions of this application.

  1. Top eight technical talents rating NetBeans 6.5
  2. Release of NetBeans IDE 6.7 beta
  3. NetBeans IDE 6.5.1 released enhanced network and Java Development
  4. The NetBeans cooperation system is becoming increasingly mature. Third-party support is gradually increasing.
  5. Added Python support for NetBeans IDE

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.