tags:

views:

38

answers:

1

I have defined the data source in struts-config.xml. I want to get a connection from it in a Struts action class.

The code is:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
    LoginForm loginForm = (LoginForm) form;
    Connection con = null;
    DataSource ds;

    try {
        ds = getDataSource(request,"A");
        con = ds.getConnection();

    } catch (Exception e) {

    }

    return null;
}

The line

        ds = getDataSource(request,"A");

gives the following compilation error:

Type mismatch: cannot convert from DataSource to DataSource

How can this happen and how can I fix this?

+1  A: 

Type mismatch: cannot convert from DataSource to DataSource

This compilation error just means that the type returned by getDataSouce() doesn't match the type as you declared the ds to be. This compilation error is also not really helpful since it doesn't include the package name. But it at least means that you're using two different DataSource classes from different packages.

You need to ensure that the type is javax.sql.DataSource everywhere.

BalusC
thanks for solution
vanita
You're welcome. Don't forget to mark the answer accepted. See also http://stackoverflow.com/faq :)
BalusC