Remote Service Question

GWT Designer allows you to quickly create the modules, composites, panels, remote services and other elements that comprise Google Web Tookit applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Remote Service Question

Postby aesrys » Mon Aug 13, 2007 4:34 am

Hello,

I'm fairly new to both Java and GWT, and need a little help with
creating a remote service. In trying to learn more about GWT, I
created a basic application based on an example at the Instantiations
website. Basically, the app pulls data from a test
table through a JDBC query and tries to put it into a grid. When I
try to run the app, I get the following error when I click the button
that should pull the data:
Code: Select all
java.lang.ClassCastException: java.lang.String cannot be cast to
query.client.QueryItems
        at query.client.QueryView$2.onSuccess(QueryView.java:60)
        at query.client.QueryService_Proxy$1.onCompletionImpl(transient
source for query.client.QueryService_Proxy:67)
        at query.client.QueryService_Proxy$1.onCompletionAndCatch(transient
source for query.client.QueryService_Proxy:43)
        at query.client.QueryService_Proxy$1.onCompletion(transient source
for query.client.QueryService_Proxy:37)
        at
com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:
126)
        at
com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:
150)
        at
com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:
293)
        at
com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:
196)
        at
org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:
117)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925)


Here's the relevant code:
Remote Service contains: List getQueryItems();

Service Async contains: void getQueryItems(AsyncCallback callback);

Service Impl contains:
Code: Select all
@Override
        public List getQueryItems() {

                final Connection con;
                final String query;
                final Statement stmt;
                final ResultSet rs;

                List li = new ArrayList();

                try {

                        // Set connection for Oracle
                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        con = DriverManager.getConnection(
                                        "jdbc:oracle:thin:@server:1521:DB", "username",
                                        "password");
                        con.setAutoCommit(false);

                        // Query string plus conditional variable(s)
                        query = "SELECT * from JH_PROG";

                        // Run query
                        stmt = con.prepareStatement(query,
                                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                                        ResultSet.CONCUR_READ_ONLY);

                        rs = stmt.executeQuery(query);

                        ResultSetMetaData rmd = rs.getMetaData();
                        int colCount = (rmd.getColumnCount() - 1);

                        // Loop through ResultSet and add values to a list
                        while (rs.next()) {

                                for (int i = 0; i <= colCount; i++) {
                                        li.add(i, rs.getObject(i + 1));
                                }
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
                return li;
        }


The view object, where the error seems to occur, has a button that
runs the following function
Code: Select all
private void getData() {
                QueryService.Util.getInstance().getQueryItems(new AsyncCallback() {
                        public void onSuccess(Object result) {
                                        List items = (List) result;
                                        grid.resize(1 + items.size(), 3);
                                        int row = 1;
                                        for (Iterator I = items.iterator(); I.hasNext(); row++) {
                                                QueryItems qi = (QueryItems) I.next();
                                                grid.setWidget(row, 0, new Label(qi.getCol1()));
                                                grid.setWidget(row, 1, new Label(qi.getCol2()));
                                                grid.setWidget(row, 2, new Label(qi.getCol3()));
                                        }
                        }

                        public void onFailure(Throwable caught) {
                        }
                });
        }

QueryItems is a simple java class that implements IsSerializable and
contains getters/setters for 3 String fields, which matches the table
(JH_PROG) from the JDBC query. Any help would be appreciated.
Code: Select all
Code: Select all
aesrys
 
Posts: 5
Joined: Wed Jul 11, 2007 12:31 pm

Problem

Postby aesrys » Mon Aug 13, 2007 7:46 am

I think I found my problem. I'm passing a List of Strings to code expecting QueryItems instead. I tested a way to fix it, but my code is definitely not elegant or probably even efficient, so I'd appreciate any suggestions/examples on how to best go about it. Thanks.
aesrys
 
Posts: 5
Joined: Wed Jul 11, 2007 12:31 pm

Re: Problem

Postby Eric Clayberg » Thu Aug 16, 2007 12:22 pm

General GWT questions are better posted to Google's GWT forum.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to GWT Designer

Who is online

Users browsing this forum: No registered users and 3 guests