Downloading and Installing NetBeans IDE

These instructions describe how to download and install NetBeans, a commonly used IDE for Java programming. Using an IDE means that you have all of the tools you need in one place (your "development environment") instead of having to organize things manually. Use the instructions in Step 2 to write a simple Java program called "Hello.java" and then compile and run it.

8. NetBeans and MySQL

Reference: "Connecting to a MySQL Database" @ http://netbeans.org/kb/docs/ide/mysql.html.

NetBeans (JavaEE) provides direct support to MySQL server. You can use NetBeans as a GUI client to access a MySQL server, as well as an administrative tool (e.g., starting and stopping the server).

Configuring NetBeans to Support MySQL

From NetBeans "Window" menu ⇒ Select "Services". The "Services" tab shall appear on the left pane

  1. Right-click on the "Databases" node ⇒ "Register MySQL Server". (If you have already registered a MySQL server, you can right-click on Server node "MySQL Server at hostname:port " ⇒ Properties, to modify its properties.)
  2. Select the "Basic Properties" tab, enter the hostname, port number, root user and password.
  3. Select the "Admin Properties" tab:
    1. Leave the "Path/URL to admin tool" empty.
    2. In "Path to start command", enter "<MYSQL_HOME>\bin\mysqld.exe"; in the "Arguments", enter "--console "
    3. In "Path to stop command", enter "<MYSQL_HOME>\bin\mysqladmin.exe", in the "Arguments", enter "-u root -ppassword shutdown ".
  4. server node "MySQL Server at hostname:port " appears.

Database Administration - Start/Stop the Server and Create Databases

  1. You can start the MySQL server by right-clicking on the server node ⇒ select "start". [There seems to be a problem here. If a "connection refused: connect" error occurs, enter the password again.]
  2. Once the MySQL server is started and connected, you can see the list of databases by expanding the MySQL server node. You can create a new database by right-clicking on it and choose "Create Database...".

Create a new Connection

You need a connection to manipulate data. You can create multiple connections with different users and default databases.

  1. Right-click on the "Databases" ⇒ "New Connection..." ⇒ Select the driver "MySQL Connector/J" ⇒ Next ⇒ Enter hostname, port number, default database, a general username and password ⇒ "Test Connection" (make sure that MySQL is started) ⇒ Finish.
  2. connection node "jdbc:mysql://hostname:port/defaultDatabase " appears.

Manipulating Data via a Connection

  1. Right-click on a connection node (e.g., "jdbc:mysql://hostname:port/defaultDatabase ") ⇒ Choose "Connect" (if not connected, provided that the MySQL server has been started).
  2. You can expand the connection node to view all the databases.
  3. Expand an existing database. There are three sub-nodes "Tables", "View" and "Procedures". Right-click on the "Tables" to create table or execute command. Similarly, right-click on the "View" and "Procedures".
  4. To view/manipulate the records in a table, right-click on the selected table ⇒ You can choose to "View Data...", "Execute Command...", etc.
  5. You can right-click on the connection to "connect" or "disconnect" from the server.

Create a SQL Script and Run the Script

You can create a SQL script by right-clicking on a project ⇒ New ⇒ "SQL File". You can run the script by right-clicking on the SQL script ⇒ "Run File" ⇒ Select an existing connection (or create a new connection) to run the script. You could also run a single statement (right-click on the statement ⇒ Run Statement) or a selected group of statements (highlight the statements ⇒ Right-click ⇒ Run Selection).