Show records from mysql to Table or DataTable

Hello:

  1. I have an short example from Vaadin discuss, and I select records from table Regions of lportal database Liferay:
    I add the portlet in liferay and the table is displayed with blank records.
    Records are selected from the ranks of the table but not shown.
    I attach a screenshot.
  2. Where can I find complete help manual with details to work with records and tables (or datatables etc …) in vaadin ?

Thanks


package com.example.mysql_c;

import com.vaadin.Application;
import com.vaadin.ui.;
import java.sql.
;
import javax.sql.;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.data.util.QueryContainer;
import com.vaadin.ui.
;

public class Mysql_cApplication extends Application {

String dbtime;
String dbUrl = "jdbc:mysql:///lportal";
String dbClass = "com.mysql.jdbc.Driver";
String query = "Select * FROM User_";
private Table tblDataTable = null;
private QueryContainer qcSQL = null;

@Override 
public void init() {
	
	 
	try {
		Connection con = DriverManager.getConnection(dbUrl, "xxxxx","yyyyy");
		
		qcSQL = new QueryContainer("SELECT * FROM Region",con);
		tblDataTable = new Table(); 

		tblDataTable.setContainerDataSource(qcSQL);
		
		tblDataTable.setVisible(true);
		tblDataTable.setEnabled(true);
		tblDataTable.setCaption("Vaadin");
		qcSQL.close();
	
	}
		catch(SQLException e) {
		e.printStackTrace();
		}
		Window mainWindow = new Window("Mysql_c Application");
		Label label = new Label("Hello Vaadin user");
		mainWindow.addComponent(label);
		mainWindow.addComponent(tblDataTable);
		setMainWindow(mainWindow);
		
	
}

}
11116.png

Never used QueryContainer, but can’t this statement break the things and produce empty table ? If you comment it out, will the table display the data ?

qcSQL.close();

Yes, I think Dmitri got it right again.

If you close the query the Table cannot pull data from the query anymore, thus leading an empty table. You should close the query only when the table is not displayed anymore.

Comment //qcSQL.close(); It works !!!
Thanks,

Regards,

I found vaadin components examples in: (Code java examples)
http://demo.vaadin.com/sampler/#Components

  1. How can I Order rows in table clicking on header of table???

       I added:  // turn on column reordering 
     	tblDataTable.setColumnReorderingAllowed(true);
    

    but columns are not enabled and does not order rows.

Thanks
11117.png

QueryContainer does not support sorting.

I would like to order rows in table clicking on header:
In code vaadin table(Grid) —> sampler (Table order):
http://demo.vaadin.com/sampler/#Components/Table%20(Grid)/TableSorting

// selectable
table.setSelectable(true);
table.setMultiSelect(true);
table.setImmediate(true); // react at once when something is selected
// connect data source

table.setContainerDataSource(ExampleUtil.getISO3166Container());

// turn on column reordering and collapsing
table.setColumnReorderingAllowed(true);
table.setColumnCollapsingAllowed(true);

  1. Which parameter in tblDataTable.setContainerDataSource(xxxxx); can I use? (Without QueryContainer)

  2. If not, Where can I find an example ExampleUtil.getISO3166Container() ?

  3. How can I change QueryContainer? in :

                   qcSQL = new QueryContainer("SELECT * FROM Region order by    regionId,countryId,regionCode,name",con);
      tblDataTable = new Table(); 
    
      tblDataTable.setContainerDataSource(qcSQL);
    

Thanks

To do that, the Container that is used with the table must implement Container.Sortable. One way would be to extend / copy QueryContainer and implement the required interface. You could look at IndexedContainer for an example implementation. (I think IndexedContainer does the sorting at java level, when a sorting QueryContainer should probably do it at database level)

Hello:
Using IndexedContainer don’t work:


qcSQL = new QueryContainer(“SELECT * FROM Region”,con);
tblDataTable = new Table();

		IndexedContainer ic = new IndexedContainer(qcSQL.getItemIds());
		
		tblDataTable.setContainerDataSource(ic);
                    tblDataTable.setVisible(true);
                    tblDataTable.setColumnReorderingAllowed(true);

The records do not show !!!

Regards,
11125.png

Hi!

I explained yesterday on
this post
why you can’t do new IndexedContainer(Collection). There is even two solutions to make it work.

Hope it helps!

Hi
How to Style cells of an row based on data . If data is fetched from Mysql. Even am using queryContainer

Thanks a lot in Advance

This question is not really related to the old thread so it would have been better to ask it separately, but: take a look at the Table.CellStyleGenerator interface. There is also
an example of it
in the Sampler.

Which version of vaadin is used?