commit new Items to Database (SQLContainer)

I have an Application which displays a Chart, which is filled with data from an SQL table. I was looking for an possibility to let the user “Edit” the table so he can change the Chart. Today I found the Vaadin “SQLContainer” Add-on which is exactly what I need. I was able to connect to the Database and get the table I need and connect it to a Vaadin Table so I get to see a Database table inside Vaadin. I’ve read the Vaadin tutorial for SQLContainer (Updated AdressBook Tutorial) quite a few times but I still don’t get how to commit something to the DB via the SQLContainer. This is what I’ve got so far:

public void displayTable(){ 
    try {
        connectionPool = new SimpleJDBCConnectionPool(
                "org.postgresql.Driver",
                "jdbc:postgresql://localhost:5432/database", "username", "password", 2, 5);
        FreeformQuery query = new FreeformQuery("select * FROM table", connectionPool);
        container = new SQLContainer(query);
        container.addListener(new QueryDelegate.RowIdChangeListener() {
            public void rowIdChange(RowIdChangeEvent event) {
                System.err.println("Old ID: " + event.getOldRowId());
                System.err.println("New ID: " + event.getNewRowId());
            }
        });
    } catch (SQLException e) {
          e.printStackTrace();
    }
    table= new Table("Table",container);
    table.setSelectable(true);
    table.addListener(this);
    window.addComponent(table);
    }

}

I’m working with Vaadin Version 6.6.6 and I use PostgrSQL.

In the AdressBookApplication example to add a new contact (Item) i have to make a new Person Bean and add it to the Container . In my case I want to add a new Column witch represents a new Chart (Jfreechart) is it even possible to add a new column ? because in the examples only rows are being added ;/

Hi,

the SQLContainer does not support adding columns to the database. You’ll have to roll your own solution for that, e.g. call a method which generates the appropriate SQL query. In any case, it does not sound reasonable to add a whole new column to the database for each new chart. Did I misunderstand something?

-Tepi

Im working with jfreechart so it uses the first column of a table as the name of the axes and the other columns as values on those axes so if i want to add something to the chart to compare with i have to add a whole column

Hi Kiesa.

Maybe you need to re-design your DB structure, one of the choices you have is to add a new column that references to another table in which you can add new rows that represents the new charts, i.e. convert the new columns into new rows in another table.

I hope that you understand what I mean, if not, feel free to ask.

Cheers

Javi

I am trying to achieve the same, i found this in the SQLContainer tutorial, so it seems to allow you to add new items to the DB. In my case i am using a Mysql database and as specified in the tutorial it seems you first have to add an item and then edit the item.

Each time i call the container.addItem() it returns null. So can someone confirm how to use the SQLContainer to add new rows to a db table?

https://vaadin.com/tutorial/sql/-/section/ch02s03.html