JDBC + Mysql

Hi, I´m trying to make a simple data insert to my database using plain jdbc but doen´t work and I don´t know what I´m doing wrong. Here´s the code of the application:

Code of the class that I use to connect with the database;

package com.example.conexao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Vanilson
 */
public class Conexao {
    private final static String driver = "com.mysql.jdbc.Driver";
    private final static String path = "jdbc:mysql://localhost:3306/vaadindatabase";
    private final static String usuario = "root";
    private final static String senha = "root";
    private static Connection conexao;

    public static Connection getConnection() {
        try {
            Class.forName(driver);
            conexao = DriverManager.getConnection(path, usuario, senha);
        } 
        catch (SQLException sqle) {
            //JOptionPane.showMessageDialog(null, "Impossivel se conectar a base de dados", "Login", JOptionPane.ERROR_MESSAGE);
        } 
        catch (ClassNotFoundException cnfe) {
            //JOptionPane.showMessageDialog(null, "Impossivel encontrar a classe driver", "Login", JOptionPane.ERROR_MESSAGE);
        }
        return conexao;
    }    
}

The pojo class

package com.example.modelo;

/**
 *
 * @author Vanilson
 */
public class Pessoa {
    private int codigo;
    private String nome;
    
    public Pessoa() {
    }

    public Pessoa(int codigo, String nome) {
        this.codigo = codigo;
        this.nome = nome;
    }

    public int getCodigo() {
        return codigo;
    }

    public void setCodigo(int codigo) {
        this.codigo = codigo;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
    
}

The Data Acess Object class

package com.example.dao;

import com.example.conexao.Conexao;
import com.example.modelo.Pessoa;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Vanilson
 */
public class PessoaDao {
    Connection conexao;
    PreparedStatement ps;
    ResultSet rs;   
    
    public PessoaDao() {
    }
    public void inserir(Pessoa p) {
        try {
            conexao = Conexao.getConnection();
            ps = conexao.prepareStatement("INSERT INTO armazem VALUES(null,?)");
            ps.setString(1, p.getNome());
            ps.executeUpdate();
            ps.close();
            conexao.close();
        } catch (SQLException exception) {
            JOptionPane.showMessageDialog(null, "Impossivel registar armazém " + exception, "Armazém", JOptionPane.ERROR_MESSAGE);
        }
    }     
}

My main class

package com.example.vaadin;           

import com.example.dao.PessoaDao;
import com.example.modelo.Pessoa;
import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
/** 
 *
 * @author Vanilson
 * @version 
 */

public class Principal extends Application {

    @Override
    public void init() {
	final Window mainWindow = new Window("Registo de pessoas");
        Label lblNome = new Label("Nome");
        final TextField txtNome = new TextField();
        Button btnSalvar = new Button ("Salvar");
        btnSalvar.addListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
                Pessoa p = new Pessoa();
                PessoaDao pd = new PessoaDao();
                p.setNome((String) txtNome.getValue());
                pd.inserir(p);
                mainWindow.showNotification("Pessoa inserida com sucesso");
                //pd.inserir(p);
            }
        });
	mainWindow.addComponent(lblNome);
        mainWindow.addComponent(txtNome);
        mainWindow.addComponent(btnSalvar);
	setMainWindow(mainWindow);
    }

It happens a strange thing when I click at the button, the loading icon at the right corner change his color from yellow to red…

Anything in server consoles etc? If the loading indicator turns red, it means that the browser is waiting for a response from server but it doesn’t return. My guess is that it hangs in either Conexao.getConnection() or ps.executeUpdate(). Are you sure that the database is up and it is working? Do you see any rows in the database table if you access it with some other tool? Have you debugged the code to see where it hangs?

A tip: code in English. Even if it is not your native language, you will still have it in your code as all the frameworks (JDBC, Vaadin, etc.) uses English, and you get easier help when you paste your code and someone else also understands it.

Jens Jansson, I resolve the problem, it was a stupid mistake (wrong table name in the PessoaDao class, the name is pessoa).

ps = conexao.prepareStatement("SELECT *FROM armazem");

Just one question, is there any problem if I keep working in this way when I´m working with database?

Thanks for the tip, starting now I will code in englsh…

Separating UI code and backend code is a good practice, as you are doing with the DAO, so I say you have a good way to do it. The reason why you got the red spinner and not an exception from the database connection is wondering me, so that is maybe something that should be looked into