Filling table with data from Database ;)

I have database set up on phpMyAdmin. I get access to it by using jdbc. And here goes my question: How can I fill table with data ?:stuck_out_tongue:
Before I used to only use JFrame, so I got this code:

public void loadData(JTable table)
	{
		try{
	        Statement st = conn.createStatement(); 
	        st.executeQuery("SELECT Title, Last_name, Publisher " +
            		"FROM order " +
            		""); 
	        ResultSet r = st.getResultSet(); 
	        
	        ResultSetMetaData meta = r.getMetaData(); 
			int cols = meta.getColumnCount(); 
			String[] headers = new String[cols]
;
			
			for(int i=0;i<cols;i++) headers[i]
 = meta.getColumnName(i+1);
			
			DefaultTableModel model = (DefaultTableModel) table.getModel();
			
			
			while(model.getRowCount() > 0)
				model.removeRow(0); 
			
			
			model.setColumnIdentifiers(headers);
			
			
			while(r.next())
			{
				String[] row = new String[cols]
; 
				
				
				 for(int i=0;i<cols;i++)
					 row[i]
 = r.getString(i+1); 
					 
				 model.addRow(row); 
				}
			
			table.setModel(model); 
		
			

	    }
	    catch (Exception e) {e.printStackTrace(); }
	        


	}

I appreciate yours fast help :wink:

What about using a BeanItemContainer?
You simply create beans, put them inside the container and set that container to the table by using the ‘setContainerDataSource’ method.
That’s all…
In addition, you might try SQLContainer, but I have no experience with it…

With your requirements I’d use SQLContainer with a FreeFormQuery. Then you can also implement writing / sorting / filtering later if needed.

There are good instructions for doing that in the Book of Vaadin
here
.

For now on I used BeanItemContainer :wink:
But I got new problem with login to my application.
Right now is something like that:

public void authenticate(ClickEvent event) {
		try{
String login = (String) loginField.getValue();
		
		if ("lisu".equals(login)) {
		getApplication().setUser(login);
		}
else {
		showNotification("You didn't exist!");
		}
}
		catch (Exception e) {e.printStackTrace(); }

But I want and change it to that my login/password would be take from DataBase. I was trying to solve it with this:

public void authenticate(ClickEvent event) {
		try{
		db.connect();
		String text = "";
		String login = (String) loginField.getValue();
		ResultSet r = db.rawQuery("SELECT login FROM log");
		while(r.next()){
		String name = r.getString("login");
		text = db.nextString("login");
		if (login.equals(name))
				{
			getApplication().setUser(login);
				}
		else {
		showNotification("You didn't exist!");
		}
	 db.close();
	}
		}
		catch (Exception e) {e.printStackTrace(); }

Anyone willing to help me ?:slight_smile: