Skip to main content

Overview

This guide will walk you through using MySQL SQL Editor for the first time. You’ll learn how to launch the application, connect to a MySQL database, browse tables, write queries, and view results.
Before starting, make sure you’ve completed the Installation steps and have a running MySQL server with at least one non-system database.

Launch the Application

1

Start MySQL SQL Editor

From your project directory, run the application:
java -cp "bin:lib/mysql-connector-j-9.2.0.jar" com.app.Main
On Windows:
java -cp "bin;lib/mysql-connector-j-9.2.0.jar" com.app.Main
The login window titled “Conexión a MySQL” will appear with a clean interface styled in the application’s primary color (#0078D7).
Create a shell script or batch file to simplify launching:Linux/macOS (run.sh):
#!/bin/bash
java -cp "bin:lib/mysql-connector-j-9.2.0.jar" com.app.Main
Windows (run.bat):
@echo off
java -cp "bin;lib/mysql-connector-j-9.2.0.jar" com.app.Main
2

Enter MySQL Credentials

In the login window, you’ll see several input fields:
  1. Servidor — Select your MySQL server host:
    • localhost (if MySQL is running on your machine)
    • 127.0.0.1 (loopback address)
    • Or a custom remote host (requires modification in View.java)
  2. Usuario — Enter your MySQL username (e.g., root, admin, or your custom user)
  3. Contraseña — Enter the password for your MySQL user
The application requires valid credentials with sufficient privileges to list and query databases. Ensure your user has at least SELECT privileges.
3

Load Available Databases

Before connecting, click the “Actualizar” button next to the Base de datos dropdown.This triggers the cargarBasesDatos() method in Controller.java, which:
  • Connects to the MySQL server using your credentials
  • Executes SHOW DATABASES to retrieve all available databases
  • Filters out system databases (information_schema, mysql, performance_schema, sys)
  • Populates the dropdown with accessible databases
// From Model.java:26-42
public List<String> obtenerTodasLasBasesDatos(String host, String usuario, String password) 
    throws SQLException {
    List<String> basesDatos = new ArrayList<>();
    String url = "jdbc:mysql://" + host + ":3306/?useSSL=false";
    
    try (Connection conn = DriverManager.getConnection(url, usuario, password);
         Statement stmt = conn.createStatement();
         ResultSet rs = stmt.executeQuery("SHOW DATABASES")) {
        
        while (rs.next()) {
            String nombreBD = rs.getString(1);
            if (!nombreBD.matches("information_schema|mysql|performance_schema|sys")) {
                basesDatos.add(nombreBD);
            }
        }
    }
    return basesDatos;
}
The application uses SwingWorker to perform database operations asynchronously, keeping the UI responsive during network calls.
After a few seconds, you should see a success message: “Bases de datos actualizadas correctamente”.
4

Select a Database

From the Base de datos dropdown, select the database you want to work with.If you don’t have any databases yet, create one in MySQL first:
CREATE DATABASE sample_db;
USE sample_db;
CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100),
  email VARCHAR(100)
);
INSERT INTO users (name, email) VALUES 
  ('Alice', '[email protected]'),
  ('Bob', '[email protected]');
5

Connect to the Database

Click the “Conectar” button to establish a connection.The application will:
  • Validate that all required fields are filled
  • Call modelo.conectar() to establish a JDBC connection
  • Retrieve the list of tables in the selected database using DatabaseMetaData
  • Hide the login window and display the SQL Editor view
// From Model.java:53-59
public void conectar(String host, String database, String usuario, String password) 
    throws SQLException {
    conexion = DriverManager.getConnection(
        "jdbc:mysql://" + host + ":3306/" + database + "?useSSL=false",
        usuario,
        password
    );
}
Upon successful connection, you’ll see the main SQL Editor window.

Explore the SQL Editor Interface

The SQL Editor window (SqlEditorView) is divided into several key areas:

Top Section: Connection Info & Controls

  • Connection Status Field — Shows “Conectado a: [database_name]” indicating the active database
  • Cambiar BD Button — Disconnect and return to the login screen to switch databases

Left Section: SQL Query Editor

  • Editor SQL Panel — Large text area with Consolas monospace font for writing SQL queries
  • Ejecutar Button (Primary blue button) — Executes the SQL query in the editor
  • Limpiar Button — Clears the query editor, results table, and system messages
  • Refrescar tablas Button — Refreshes the list of tables in the right panel

Right Section: Table Browser

  • Tablas disponibles — A list showing all tables in the connected database
  • Double-click functionality — Double-clicking a table name auto-generates a SELECT * FROM [table] LIMIT 100 query
// From SqlEditorView.java:146-156
listaTablas.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent evt) {
        if (evt.getClickCount() == 2) {
            String tablaSeleccionada = listaTablas.getSelectedValue();
            if (tablaSeleccionada != null) {
                String consulta = "SELECT * FROM " + tablaSeleccionada + " LIMIT 100";
                txtConsulta.setText(consulta);
            }
        }
    }
});

Bottom Section: Results Display

  • Resultados Panel — Table view displaying query results with columns and rows
  • Mensaje del sistema Label — Shows status messages like “Consulta ejecutada correctamente” or error details

Execute Your First Query

1

Write a SELECT Query

In the Editor SQL text area, type a simple query:
SELECT * FROM users;
Or double-click a table name in the Tablas disponibles list to auto-generate a SELECT query with LIMIT 100.
2

Execute the Query

Click the “Ejecutar” button (primary blue button on the right side).The application will:
  1. Validate that the query is not empty
  2. Execute the query using modelo.ejecutarConsulta()
  3. Parse the ResultSet and build a DefaultTableModel
  4. Display results in the Resultados table
  5. Show “Consulta ejecutada correctamente” in the system message label
// From Model.java:106-122 (SELECT query handling)
if (trimmedQuery.startsWith("select")) {
    try (ResultSet rs = stmt.executeQuery(query)) {
        ResultSetMetaData meta = rs.getMetaData();
        int columnas = meta.getColumnCount();
        
        for (int i = 1; i <= columnas; i++) {
            modelo.addColumn(meta.getColumnName(i));
        }
        
        while (rs.next()) {
            Object[] fila = new Object[columnas];
            for (int i = 0; i < columnas; i++) {
                fila[i] = rs.getObject(i + 1);
            }
            modelo.addRow(fila);
        }
    }
}
3

View Results

The results appear in the Resultados panel with:
  • Column headers extracted from the ResultSetMetaData
  • All rows returned by your query
  • Organized in a clean table format with 22px row height
For large result sets, the table automatically adds a scrollbar. Results are displayed with zero grid spacing for a clean, modern look.

Try Different Query Types

MySQL SQL Editor supports all SQL statement types. Let’s explore common operations:

INSERT Query

Add new data to your table:
INSERT INTO users (name, email) VALUES ('Charlie', '[email protected]');
After executing an INSERT query, the application automatically:
  1. Executes the statement using stmt.executeUpdate()
  2. Extracts the table name from the query
  3. Re-queries the table with SELECT * FROM users
  4. Displays the updated table contents
This automatic refresh lets you immediately see your inserted data without manually re-running a SELECT query.

UPDATE Query

Modify existing records:
UPDATE users SET email = '[email protected]' WHERE name = 'Alice';
The application will show the updated table contents and display “Filas afectadas: 1” in the results.

DELETE Query

Remove records from a table:
DELETE FROM users WHERE id = 3;

CREATE TABLE Query

Define new table structures:
CREATE TABLE products (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100),
  price DECIMAL(10, 2)
);
After creating a table, click “Refrescar tablas” to update the table list in the right panel.

Browse Tables with Quick Select

1

View Available Tables

The Tablas disponibles panel on the right shows all tables in your connected database.This list is populated by calling modelo.obtenerTablasDeBaseDatos():
// From Model.java:78-90
public List<String> obtenerTablasDeBaseDatos() throws SQLException {
    List<String> tablas = new ArrayList<>();
    if (conexion != null && !conexion.isClosed()) {
        DatabaseMetaData metaData = conexion.getMetaData();
        String catalogoActual = conexion.getCatalog();
        try (ResultSet rs = metaData.getTables(catalogoActual, null, "%", new String[]{"TABLE"})) {
            while (rs.next()) {
                tablas.add(rs.getString("TABLE_NAME"));
            }
        }
    }
    return tablas;
}
2

Generate Query with Double-Click

Double-click any table name in the list.The application automatically generates and inserts this query into the editor:
SELECT * FROM [table_name] LIMIT 100
The LIMIT 100 clause prevents accidentally loading massive datasets into the UI, keeping the application responsive.
3

Execute the Generated Query

Simply click “Ejecutar” to run the auto-generated query and view the table contents.

Clear and Reset

To start fresh:
  1. Click the “Limpiar” button
  2. This clears:
    • The SQL query editor
    • The results table
    • Any system messages
// From SqlEditorView.java:281-285
public void limpiar() {
    txtConsulta.setText("");
    tblResultados.setModel(new DefaultTableModel());
    lblMensajeSistema.setText(" ");
}

Switch Databases

To connect to a different database:
1

Click 'Cambiar BD'

Click the “Cambiar BD” button in the top-right area.
2

Confirm Disconnection

A confirmation dialog appears: “¿Desea desconectarse y cambiar de base de datos?”Click Yes to proceed.
3

Return to Login

The SQL Editor window closes, and you return to the login screen.The application calls modelo.desconectar() to properly close the JDBC connection:
// From Model.java:66-70
public void desconectar() throws SQLException {
    if (conexion != null && !conexion.isClosed()) {
        conexion.close();
    }
}
4

Connect to New Database

Select a different database from the dropdown and click “Conectar” again.

Error Handling

The application provides clear error messages for common issues:

Empty Query Error

If you click “Ejecutar” without writing a query, you’ll see:
“Ingrese una consulta SQL” warning dialog

SQL Syntax Errors

If your query has syntax errors, the application displays:
  • An error dialog with the MySQL error message
  • The system message label shows: “Error: [error details]“

Connection Issues

If the connection to MySQL is lost, error dialogs appear with detailed messages from the JDBC driver.

Tips for Efficient Use

Use Double-Click

Double-click table names to instantly generate SELECT queries—saves typing and reduces errors

Limit Large Queries

Always use LIMIT clauses when querying large tables to keep the UI responsive

Refresh Tables

After CREATE TABLE or DROP TABLE operations, click “Refrescar tablas” to update the table list

Check System Messages

Watch the system message label for execution status and row counts

Next Steps

Now that you’ve mastered the basics, explore more advanced topics:

User Guide

Learn advanced connection management and database operations

Architecture

Understand how the MVC pattern powers the application
Pro tip: The application’s asynchronous architecture using SwingWorker ensures the UI never freezes during long-running queries. You can always monitor progress through the system message label.

Build docs developers (and LLMs) love