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