Need Help for gwt-rpc mysql database connectivity

505 views
Skip to first unread message

Dilip Rathod

unread,
Mar 14, 2011, 8:04:53 AM3/14/11
to Google Web Toolkit
I can gwt-rpc communication with server sucessfully.
but when i want to interact with mysql I get following error

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
Could not create connection to database server.

I added mysql connector to WEB-Inf/lib dierctory

following is my code that tries to connect to data base

public String login(String usr,String pwd)
{
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/
SeekwadiDataBank";
String db = "SeekwadiDataBank";
String driver = "com.mysql.jdbc.Driver";
String user = "user";
String pass = "user";
String connerr=null;
try
{
connerr="Connecting ....";
Class.forName(driver).newInstance();
connerr+="Still Working....";
//Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, pass);
connerr="Conncted....";
} catch (Exception e) {
// TODO: handle exception
connerr+=e.toString();

}
return connerr;
}


i cannot give full stack trace becuse it is not available at client
side

client side code taht communicate asynchronoulsy to server is

Hyperlink login = new Hyperlink("Login", "Login");
login.addClickListener(new ClickListener() {
public void onClick(Widget widget)
{
hp.clear();
final TextBox usr=new TextBox();
final PasswordTextBox pwd=new PasswordTextBox();

Button loginb=new Button("Login");
loginb.addClickHandler(new ClickHandler()
{
public void onClick(ClickEvent event)
{ //Window.alert("Starts");
AsyncCallback callback = new AsyncCallback()
{

public void onSuccess(Object result)
{
if(((String) result).equals("Ok"))
{ Window.alert("Login Status:"+result.toString());
usr.setText(""); pwd.setText(""); }
else { Window.alert("Login
Status:"+result.toString()); usr.setText(""); pwd.setText(""); }
}
public void onFailure(Throwable caught)
{ Window.alert(caught.getMessage()); }
};
no.login(usr.getText(),pwd.getText(), callback);
//Window.alert("Ends");
}

});

Juan Pablo Gardella

unread,
Mar 14, 2011, 4:03:23 PM3/14/11
to google-we...@googlegroups.com
This help? http://stackoverflow.com/questions/2297356/mysqlnontransientconnectionexception-in-jdbc-program-at-run-time

Juan

2011/3/14 Dilip Rathod <rath...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Ben Imp

unread,
Mar 14, 2011, 4:08:54 PM3/14/11
to Google Web Toolkit
I am quite curious how it is that you can not have access to the
server side stack trace. I suspect the answer to your question lies
there.

-Ben

Dilip Rathod

unread,
Mar 15, 2011, 1:57:35 AM3/15/11
to google-we...@googlegroups.com
I cannot connect to database in development mode/hosted mode.
my environment: eclipse hellio 3.6, fedora 12, mysql, gwt2.2.

I could successfully connect to mysql using JSP using same environment.

Sean

unread,
Mar 15, 2011, 8:20:38 AM3/15/11
to google-we...@googlegroups.com
This is more for Ben then the original poster, but you can make your own serializble exception, catch the exception on the server side and then throw your Serializable Exception with the original message in it. It makes RCP so much easier to debug.


Ben Imp

unread,
Mar 15, 2011, 11:53:50 AM3/15/11
to Google Web Toolkit
Yeah, I've been meaning to do something like that in my application.
The current lack of details on the client isn't very pleasant for
users or developers. SSH-ing into the prod server is annoying as
well. I'm always worried about breaking something with a twitchy rm -
rf finger.

I'm still curious as to why OP can't see the logs in his server,
though. If it happens in development mode, odds are the server
console is right there in eclipse, full stack trace and all.

-Ben

Dilip Rathod

unread,
Mar 16, 2011, 2:25:18 AM3/16/11
to google-we...@googlegroups.com
Tanks Ben, Jaun for taking interest in my difficulties.

I finnaly got stack trace. In fact I am new to gwt & eclipse, good knowledge of java.
But things are not turning as i expect. So can any body give me some detailed steps to connect to mysql in development mode.


        Connection conn     = null;
        String url          = "jdbc:mysql://localhost:3306/SeekwadiDataBank";
        String driver       = "com.mysql.jdbc.Driver";
        String user         = "user";          String pass         = "user";

Class.forName(driver).newInstance();   ==================> works fine

conn = DriverManager.getConnection(url, user, pass); =============>problamatic whose stacktrace is given below

I thank in advance


com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:112)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:120)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.Util.getInstance(Util.java:384)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2355)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance_(Runtime.java:112)
    at com.google.appengine.tools.development.agent.runtime.Runtime.newInstance(Runtime.java:120)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
    at java.sql.DriverManager.getConnection(DriverManager.java:620)
    at java.sql.DriverManager.getConnection(DriverManager.java:200)
    at com.demo.server.GeneralServiceImpl.login(GeneralServiceImpl.java:59)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission localhost resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:393)
    at java.security.AccessController.checkPermission(AccessController.java:553)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:166)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1048)
    at java.net.InetAddress.getAllByName0(InetAddress.java:1189)
    at java.net.InetAddress.getAllByName(InetAddress.java:1128)
    at java.net.InetAddress.getAllByName(InetAddress.java:1064)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:246)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)
    ... 51 more


Khanh Dao Minh

unread,
Mar 17, 2011, 4:42:01 AM3/17/11
to google-we...@googlegroups.com
It sound you need a SocketPermission. Try this: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/appA.html#SocketPermission

Regards,
KhanhDM.
Reply all
Reply to author
Forward
0 new messages