Show This document demonstrates how to set up a connection to a MySQL database from the NetBeans IDE. Once connected, you can begin working with MySQL in the IDE’s Database Explorer by creating new databases and tables, populating tables with data, and running SQL queries on database structures and content. This tutorial is designed for beginners with a basic understanding of database management, who want to apply their knowledge to working with MySQL in NetBeans IDE. MySQL is a popular Open Source relational database management system (RDBMS) commonly used in web applications due to its speed, flexibility and reliability. MySQL employs SQL, or Structured Query Language, for accessing and processing data contained in databases. Configuring MySQL Server PropertiesNetBeans IDE comes bundled with support for the MySQL RDBMS. Before you can access the MySQL Database Server in NetBeans IDE, you must configure the MySQL Server properties.
Notice that the IDE enters
The Admin Properties tab is then displayed, allowing you to enter information for controlling the MySQL Server.
Type any arguments for the admin tool in the Arguments field.
Type any arguments for the start command in the Arguments field.
Starting the MySQL ServerBefore you can connect to a MySQL Database Server, you must first ensure that the MySQL Database Server is running on your machine. If the database server is not connected you will see (disconnected) next to the user name in the MySQL Server node in the Service window and you will not be able to expand the node. To connect to the database server, confirm that the MySQL Database Server is running on your machine, right-click the Databases > MySQL Server node in the Services window and choose Connect. You might be prompted to supply a password to connect to the server. When the server is connected you will be able to expand the MySQL Server node and view the all available MySQL databases. Creating and Connecting to the Database InstanceA common way of interacting with databases is through an SQL editor. NetBeans IDE has a built-in SQL Editor for this purpose.
The SQL Editor is generally accessible via the Execute Command option from the right-click menu of the connection node (or of the connection node’s child nodes). Now that you are connected to the MySQL server, you can create a new database instance using the SQL Editor. For purposes of this tutorial, create an instance called
The Create MySQL Database dialog box opens.
The new database appears under the MySQL Server node in the Services window.
Database connections that are open are represented by a complete connection node () in the Services window. Creating Database TablesNow that you have connected to ``MyNewDatabase`` is currently empty. In the IDE it is possible to add a database table by either using the Create Table dialog, or by inputting an SQL query and running it directly from the SQL Editor. In the following exercises you will use the SQL editor to create the `Counselor` table and the Create Table dialog box to create the `Subject` table. After you create the tables you will run an SQL script to populate the tables.
Using the SQL EditorIn this exercise you will use the SQL editor to create the
Using the Create Table DialogIn this exercise you will
use the Create Table dialog box to create the
You are creating a table named
Make sure that the fields
in your Create Table dialog match those shown above, then click OK. The IDE generates the Working with Table DataIn order to work with table data, you can make use of the SQL Editor in
NetBeans IDE. By running SQL queries on a database, you can add, modify and delete data maintained in database structures. To add a new record (row) to the
Running an SQL ScriptAnother way to manage table data in NetBeans IDE is by running an external SQL script directly in the IDE. If you have created an SQL script elsewhere, you can simply open it in NetBeans IDE and run it in the SQL Editor. For demonstrative purposes, download ifpwafcad.sql and save it to a location on your computer. This script creates two tables similar to what you just created above ( Because
the script overwrites these tables if they already exist, delete the
When you click Yes in the Confirm Object Deletion dialog box, the table nodes are automatically removed from the Database Explorer. To run the SQL script on
ConclusionThis concludes the Connecting to a MySQL Database tutorial. This document demonstrated how to configure MySQL on your computer and set up a connection to the database server from NetBeans IDE. It also described how to work with MySQL in the IDE’s Database Explorer by creating new database instances and tables, populating tables with data, and running SQL queries. |