Wednesday, October 30, 2013

GWT RPC AsyncCallBack is always failing persistently.

I'm trying to retrieve data from database with GWT and RPC. 

public class MySQLConnection extends RemoteServiceServlet implements Connection{
private Connection conn = null;
private ResultSet rs = null;
    private PreparedStatement pstmt = null;
public static Connection getConnection() throws Exception {
   String driver = "com.mysql.jdbc.Driver";
   String url = "jdbc:mysql://localhost:3306/temperature";
   String username = "root";
   String password = "123456";
   Connection conn = DriverManager.getConnection(url, username, password);
   return conn;
public String[] sensor() throws Exception{
String [] user = null;
try {
     conn = getConnection();
     String query = "SELECT ID, times FROM sensor ORDER BY id DESC LIMIT 1;";

     pstmt = conn.prepareStatement(query); // create a statement
     pstmt.setInt(1, 1001); // set input parameter
     rs = pstmt.executeQuery();
     // extract data from the ResultSet
     while ( {
       user = new String[] {rs.getString(1),rs.getString(2)};
   } catch(SQLException e) {
   } finally {
     try {
     } catch (SQLException e) {
   return user;
public String[] sensors() throws Exception{
return sensor();

This is the server side programming where I would return 2 parameters to the client side which will then be shown in the web application. However it is always unsuccessful as it is always onFailure that is occuring.

btnNewButton.addClickListener(new ClickListener() {
public void onClick(Widget event) {
ConnectionAsync Abra =(ConnectionAsync) GWT.create(Connection.class);
ServiceDefTarget target = (ServiceDefTarget) Abra;
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
AsyncCallback callback = new AsyncCallback(){
public void onSuccess (Object result){
Hi.setText("You Pass!");
public void onFailure(Throwable caught) {
Hi.setText("You fail!");

This is my program on the client side.

Hope if anyone would help me with this
With Regards,
Zhen Liang

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment