开发者

oracle jdbc jface wizardpage

开发者 https://www.devze.com 2023-01-05 23:49 出处:网络
I want to create a jface wizard and collect credentials as I go along - password and username on pag开发者_JS百科e 1 and then on page 2 I want to display a list I get from an oracle database.

I want to create a jface wizard and collect credentials as I go along - password and username on pag开发者_JS百科e 1 and then on page 2 I want to display a list I get from an oracle database.

I am using eclipse, and have all the controls in the places I want. On page 2 I put the oracle connection details and sql statement in the createControl method of wizardpage. This seems to fail with a class not found (ojdbc6.jar included in my build path) which I can't decide whether this is an eclipse issue or my code (my code works when it is standalone, not in a wizard)

The failure happens when I start the wizardpage, which it probably will do as I havent got the correct credentials at that point. I couldn't find a method in the wizardpage documentation for running stuff when you enter that wizardpage. Is there a method that runs on entry?

I want to connect to the database to pull down a list to populate a table.

Cheers

David


The createControl method gets called on all pages when the Wizard is opened. You should use createControl only to layout SWT or JFace objects.

You probably want to initialize the JDBC connection when the second page becomes visible. At that point you would then load your list on the page. To do that, override the setVisible method on the second page as follows:

/* (non-Javadoc)
 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
 */
@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if(visible){
        // initialize the jdbc connection here - use a data access object
        // use the connection or the DAO to populate your list
    }
}

This way the connection will be initialized when the second page becomes visible. Another useful thing to do from the setVisible method is to assign the focus to the right control by calling forceFocus() on the relevant control.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号