How can i display a table from database into mainwindow

Hi
Thanks for the previous answers. I am a new user of vaadin framework. My problem is displaying the Table in Mainwindow from the database instead of displaying in console. Is it possible in vaadin framework? I have connected to the database by using JDBC.

When i was trying to display the table in mainwindow, i got the following statement instead of the content of the data.

             [color=#EB1713]

" org.postgresql.jdbc4.Jdbc4ResultSet@1a4ded3 "
[/color]

Please give me a suggestion to solve this problem.[color=#E62929]

[/color]

Hi


org.postgresql.jdbc4.Jdbc4ResultSet@1a4ded3
, It shows that object is created for ResultSet.that means you have connected database and table that you desired, and Data fetched from table into Resultset, now you need to go through Resultset to fetch data from it. that only you need to do.

and Now what you try to do. you just try to fetch data from database table and need to display in mainwindow? or you need to display in table control in main Window? Is this your question?.. Ok any way. I will explain both.

see blow code will work .

package pack1;
import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.event.Action;
import com.vaadin.ui.*;
import com.vaadin.ui.Component.Event;
import com.vaadin.ui.Window;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.GridLayout;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;

public class MyApplication extends Application
{
Table table;
Window main = new Window(“Sample”);
Connection con;
PreparedStatement ps;
Statement cs;
ResultSet rs;
String dbUrl=“jdbc:mysql://localhost:3306/yourdatabasename”;
public void init()
{
setMainWindow(main);
table = new Table();
table.setStyleName(“iso3166”);
table.setPageLength(6);
table.setSizeFull();
table.setSelectable(true);
table.setMultiSelect(false);
table.setImmediate(true);
table.setColumnReorderingAllowed(true);
table.setColumnCollapsingAllowed(true);
/* Define the names and data types of columns.
* The “default value” parameter is meaningless here. */
table.addContainerProperty(“NAME”,String.class, null);
table.addContainerProperty(“CODE”, Integer.class, null);

         /* Add a few items in the table. */
        try{

    con = DriverManager.getConnection(dbUrl, "root","root");    
           cs = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
           rs = cs.executeQuery("select Name,Code from tablename");
           while(rs.next())
           {
             table.addItem(new Object[]{rs.getString(1), rs.getInt(2)}, rs.getInt(2));
           }
    }
    catch(Exception e)
    {
                         // getWindow(null).showNotification("Error");
    }
        table.setWidth("300px");
         table.setHeight("150px");

main.addComponent(table);
}
}

In this above code, I just try to fetch Name,Code value from my database table and put in vaadin table control and table is added in mainwindow… Now your database table data will display in mainwindow table control. Its just simple. Just to try work fine.

Thanks