0

I'm fairly new to gwt, and figuring out the connections with a mysql database has me stumped. Since there are very few direct tutorials, I've been going off another stackoverflow question here.

http://stackoverflow.com/questions/8335322/java-gwt-mysql-connection-refused/8388422#8388422

Although I can't get it right. Few things, this project isn't using the GAE, just the GWT, as was suggested as a previous answer in the other question. Yes, I can connect to my database through another sample program, so the link to the database is open. I also imported my mysql driver to /WEB-INF/lib, as well as added it to my java build path.

The crux of this is, I don't know why I can't connect, and my console is useless, if anyone can see right off the bat what I'm doing wrong that would be fantastic, or if there was a way to print out more of the error message that would be great as well as I don't know how to view the console for the server side resources (I read somewhere that there might be more to the errors then what is shown? ) thanks.

here is my GreetingServiceImpl.java relevant code

 private final Connection connect() {
    String driver = "com.mysql.jdbc.Driver";
    String dblink = "jdbc:mysql://localhost:3306/";
    String dbname = "gwttest";
    String dbuser = "user";
    String dbpass = "test";
    try {
      Class.forName(driver).newInstance();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    Connection conn = null;
    try {
      conn = DriverManager.getConnection(dblink + dbname, dbuser, dbpass);

    } catch (SQLException e) {
      System.err.println("mysql connection error: ");
      e.printStackTrace();
    }
    return conn;
  }

here is my helloserver.java relevant code

Button b = new Button("test");
vPanel.add(b);
b.addClickHandler(new ClickHandler() {
  @Override
  public void onClick(ClickEvent event) {
      GreetingServiceAsync testservice= (GreetingServiceAsync) GWT.create(GreetingService.class);
    testservice.echo("test", new AsyncCallback<String>() {

        @Override
        public void onFailure(Throwable caught) {
            // TODO Auto-generated method stub
             vPanel.add(new Label("error"));
             //vPanel.add(new Label(caught.printStackTrace());
             caught.printStackTrace();
        }

        @Override
        public void onSuccess(String result) {
            // TODO Auto-generated method stub
            vPanel.add(new Label(result));
        }

    });
  }
});

here is the error message I've recieved upon running and clicking the button (besides the "error" which pops up in my html)

 com.google.gwt.user.client.rpc.StatusCodeException: 404 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 NOT_FOUND</title>
</head>
<body><h2>HTTP ERROR: 404</h2><pre>NOT_FOUND</pre>
<p>RequestURI=/helloserver/greet</p><p><i><small><a href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br/>                                                
</body>
</html>
at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:209)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)

1 Answer 1

1

The error is indicating a problem with the RPC. Database connection problems should cause an exception to be serialized to the client, not give a 404. Check that the web.xml and servlet are configured correctly. See: https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC.

If there were any JDBC errors, then they should be visible in the DevMode window, or in the server's log directory if running on a server. It looks like the GreetingServiceImpl class isn't reached at all though so there won't see anything there.

It may be easier to extract the JDBC code to a separate class, and test it separately from GWT. Get one thing working before combining everything together. Run it via a main method, or JUnit test, then you know whether the problem is with the JDBC code or elsewhere.

Sign up to request clarification or add additional context in comments.

1 Comment

You were correct, I had changed the web.xml file and forgot to change it back. I reverted back to the original and my issues were solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.