Hello everyone,

I am trying to connect a MySQL database to a simple GWT application. I
build a simple application from scratch using the eclipse plugin. This
application runs correctly.

I changed the GreetingServiceImpl.java file as follow. And there is no
way to run it correctly. Following the code you can find a copie from
the console output.

I run a copy of this class outside GWT, and it runs correctly.
Directly with java command line and within eclipse.

The library mysql-connector-java-5.1.7-bin.jar is in the classpath and
in the reference libraries of the eclipse project.

package test.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import test.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings("serial")
public class GreetingServiceImpl extends RemoteServiceServlet
implements
                GreetingService {

        public String greetServer(String input) {
                testConnection();
                String serverInfo = getServletContext().getServerInfo();
                String userAgent = 
getThreadLocalRequest().getHeader("User-Agent");
                return "Hello, " + input + "!<br><br>I am running " + serverInfo
                                + ".<br><br>It looks like you are using:<br>" + 
userAgent;

        }
        private void testConnection() {

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try {

            /*  Register the driver
                The following Class.forName() statement is not necessary if 
using
Java SE 6 (1.6) or later */

            Class.forName("com.mysql.jdbc.Driver").newInstance();

            try {

                /* Get a connection to the database */
                conn = DriverManager.getConnection("jdbc:mysql://
localhost:3306/testbase?" + "user=usertestbase&password=pass");

                try {

                    stmt = conn.createStatement();

                    /* Execute the query */
                    rs = stmt.executeQuery("SELECT * FROM table1");

                    /* The following 3 lines are for finding out the
size of the result set */
                    rs.last();
                    int rowCount = rs.getRow();
                    rs.beforeFirst();

                    System.out.println("Retrieved " + rowCount + " row
(s).\n");

                    System.out.println("CityName\n--------");

                    /* Retrieve the data from the result set */
                    while (rs.next()) {
                        String name = rs.getString("name");
                        System.out.println(name);
                    }

                } finally {
                    /* Release the resources */
                    if (rs != null) {
                        try {
                            rs.close();
                        } catch (SQLException sqlEx) {
                               System.out.println("SQLException: " +
sqlEx.getMessage());
                        }
                        rs = null;
                    }

                    if (stmt != null) {
                        try {
                            stmt.close();
                        } catch (SQLException sqlEx) {
                               System.out.println("SQLException: " +
sqlEx.getMessage());
                        }

                        stmt = null;
                    }

                    if (conn != null) {
                        try {
                            conn.close();
                        } catch (SQLException sqlEx) {
                               // Ignore
                        }

                        conn = null;
                    }

                }

            } catch (SQLException ex) {
                System.out.println("SQLException: " + ex.getMessage
());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode
());
            }

        } catch (Exception ex) {
            System.out.println("Exception: " + ex.getMessage
());
        }

        }
}

The server is running at http://localhost:8080/
15 juin 2009 12:09:06
com.google.appengine.tools.development.ApiProxyLocalImpl log
SEVERE: [1245067746141000] javax.servlet.ServletContext log: Exception
while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract java.lang.String
test.client.GreetingService.greetServer(java.lang.String)' threw an
unexpected exception: java.lang.ExceptionInInitializerError
        at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure
(RPC.java:360)
        at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse
(RPC.java:546)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall
(RemoteServiceServlet.java:166)
        at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost
(RemoteServiceServlet.java:86)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1093)
        at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
(TransactionCleanupFilter.java:43)
        at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter
(ServletHandler.java:1084)
        at org.mortbay.jetty.servlet.ServletHandler.handle
(ServletHandler.java:360)
        at org.mortbay.jetty.security.SecurityHandler.handle
(SecurityHandler.java:216)
        at org.mortbay.jetty.servlet.SessionHandler.handle
(SessionHandler.java:181)
        at org.mortbay.jetty.handler.ContextHandler.handle
(ContextHandler.java:712)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
        at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle
(DevAppEngineWebAppContext.java:54)
        at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:139)
        at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:306)
        at org.mortbay.jetty.handler.HandlerWrapper.handle
(HandlerWrapper.java:139)
        at org.mortbay.jetty.Server.handle(Server.java:313)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
506)
        at org.mortbay.jetty.HttpConnection$RequestHandler.content
(HttpConnection.java:844)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
        at org.mortbay.io.nio.SelectChannelEndPoint.run
(SelectChannelEndPoint.java:396)
        at org.mortbay.thread.BoundedThreadPool$PoolThread.run
(BoundedThreadPool.java:442)
Caused by: java.lang.ExceptionInInitializerError
        at com.mysql.jdbc.NonRegisteringDriver.connect
(NonRegisteringDriver.java:282)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at test.server.GreetingServiceImpl.testConnection
(GreetingServiceImpl.java:43)
        at test.server.GreetingServiceImpl.greetServer
(GreetingServiceImpl.java:20)
        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.user.server.rpc.RPC.invokeAndEncodeResponse
(RPC.java:527)
        ... 25 more
Caused by: java.security.AccessControlException: access denied
(java.lang.RuntimePermission modifyThreadGroup)
        at java.security.AccessControlContext.checkPermission(Unknown Source)
        at java.security.AccessController.checkPermission(Unknown Source)
        at java.lang.SecurityManager.checkPermission(Unknown Source)
        at com.google.appengine.tools.development.DevAppServerFactory
$CustomSecurityManager.checkPermission(DevAppServerFactory.java:122)
        at com.google.appengine.tools.development.DevAppServerFactory
$CustomSecurityManager.checkAccess(DevAppServerFactory.java:149)
        at java.lang.ThreadGroup.checkAccess(Unknown Source)
        at java.lang.Thread.init(Unknown Source)
        at java.lang.Thread.<init>(Unknown Source)
        at java.util.TimerThread.<init>(Unknown Source)
        at java.util.Timer.<init>(Unknown Source)
        at java.util.Timer.<init>(Unknown Source)
        at com.mysql.jdbc.ConnectionImpl.<clinit>(ConnectionImpl.java:208)
        ... 35 more


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

Reply via email to