JDBC Connection on GWT

1,039 views
Skip to first unread message

Jose Luis Hernandez

unread,
Apr 5, 2011, 7:57:20 AM4/5/11
to Google Web Toolkit
Hello!
I am trying to connect my gwt server with postgreSQL database, but I
do not get it. It appears the following error message:

[ERROR] javax.servlet.ServletContext log: Exception while dispatching
incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract boolean
com.gwt.app.client.GreetingService.greetServer(java.lang.String,java.lang.String)
throws java.lang.Exception' threw an unexpected exception:
java.lang.NoClassDefFoundError: org.postgresql.core.Logger is a
restricted class. Please see the Google App Engine developer's guide
for more details.
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
385)
at
com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:
588)
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:351)
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.lang.NoClassDefFoundError: org.postgresql.core.Logger
is a restricted class. Please see the Google App Engine developer's
guide for more details.
at
com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:
51)
at org.postgresql.Driver.<clinit>(Driver.java:55)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.gwt.app.server.ManejadorBD.checkUser(ManejadorBD.java:10)
at
com.gwt.app.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:
15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
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)
... 30 more

I have two classes on server side, "GreetingServiceImpl" and
"ManejadorBD". The first one calls to method "checkUser" from the
second class. "ManejadorBD" is like the following code:

public class ManejadorBD {
public boolean checkUser(String user, String pass) throws Exception{
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://
localhost:5432/3encult","3encult","3encult");
Statement instruccion = conn.createStatement();
ResultSet tabla = instruccion.executeQuery("SELECT user,password
FROM user");
if(user == tabla.getString(0) && pass == tabla.getString(1)) return
true;
else return false;
}
}

Could someone help me??
Thanks in advance!
Regards!!!!

Juan Pablo Gardella

unread,
Apr 5, 2011, 2:51:15 PM4/5/11
to google-we...@googlegroups.com
Put postgresql driver in WEB-INF/lib

Juan

2011/4/5 Jose Luis Hernandez <jose.her...@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.


Paul Robinson

unread,
Apr 5, 2011, 3:16:04 PM4/5/11
to google-we...@googlegroups.com
You can't access a regular SQL DB if you're using google app engine. Either turn off the GAE setting or use GAE compatible data access.

Jose Luis Hernandez

unread,
Apr 6, 2011, 8:58:57 AM4/6/11
to Google Web Toolkit
Well, the new error is:

[ERROR] javax.servlet.ServletContext log: Exception while dispatching
incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract boolean
com.gwt.app.client.GreetingService.greetServer(java.lang.String,java.lang.String)
throws java.lang.Exception' threw an unexpected exception:
java.lang.NoClassDefFoundError: java.net.Socket is a restricted class.
Caused by: java.lang.NoClassDefFoundError: java.net.Socket is a
restricted class. Please see the Google App Engine developer's guide
for more details.
at
com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:
51)
at org.postgresql.core.PGStream.<init>(PGStream.java:62)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:
76)
at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:
66)
at
org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:
125)
at
org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:
30)
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:
24)
at org.postgresql.Driver.makeConnection(Driver.java:393)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.gwt.app.server.ManejadorBD.checkUser(ManejadorBD.java:11)
at
com.gwt.app.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:
15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
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)
... 30 more

On Apr 5, 8:51 pm, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> Put postgresql driver in WEB-INF/lib
>
> Juan
>
> 2011/4/5 Jose Luis Hernandez <jose.hernande...@gmail.com>

Jose Luis Hernandez

unread,
Apr 6, 2011, 9:11:01 AM4/6/11
to Google Web Toolkit
I am trying to access via HSQLDB. My class is:
public class ManejadorBD {
public boolean checkUser(String user, String pass) throws Exception{
Class.forName("org.hsqldb.jdbcDriver");
Properties prop = new Properties();

prop.load(this.getClass().getResource("database.properties").openStream());

JDBCDriver driver = new JDBCDriver();
Connection conn = driver.connect("jdbc:postgresql://localhost:
5432/3encult", prop);
String sql = "SELECT login,password FROM \"user\"";
Statement statement = (JDBCStatement) conn.createStatement();
ResultSet tabla = statement.executeQuery(sql);
while(tabla.next()){
if(user == tabla.getString("login") && pass ==
tabla.getString("password")) return true;
else return false;
}
}
}

And the properties file is:
user=3encult
password=3encult

But the connection object is null, what coult the problem be?
Thanks!
Regars!

Juan Pablo Gardella

unread,
Apr 6, 2011, 9:14:32 AM4/6/11
to google-we...@googlegroups.com
You are used restricted classes: java.lang.NoClassDefFoundError: java.net.Socket is a restricted class.

See whitelist classes

2011/4/6 Jose Luis Hernandez <jose.her...@gmail.com>

Jose Luis Hernandez

unread,
Apr 6, 2011, 10:13:06 AM4/6/11
to Google Web Toolkit
then, how can I access to pastgres database? Because I am using the
java.sql package that is permited.

On Apr 6, 3:14 pm, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> You are used restricted classes: java.lang.NoClassDefFoundError:
> java.net.Socket is a restricted class.
>
> See whitelist <http://code.google.com/appengine/docs/java/jrewhitelist.html>
> classes
>
> 2011/4/6 Jose Luis Hernandez <jose.hernande...@gmail.com>
> ...
>
> read more »

Juan Pablo Gardella

unread,
Apr 6, 2011, 10:15:35 AM4/6/11
to google-we...@googlegroups.com
Are you do an Google  App Engine Application or a simple GWT applitacion? If is a GWT application, remove of project configuration that use GAE SDK.

2011/4/6 Jose Luis Hernandez <jose.her...@gmail.com>
then, how can I access to pastgres database? Because I am using the

--

Jose Luis Hernandez

unread,
Apr 6, 2011, 10:22:08 AM4/6/11
to Google Web Toolkit
It is an application, but in future it should be integrated into OSGi,
then deploy in Felix server!

On Apr 6, 4:15 pm, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> Are you do an Google  App Engine Application or a simple GWT applitacion? If
> is a GWT application, remove of project configuration that use GAE SDK.
>
> 2011/4/6 Jose Luis Hernandez <jose.hernande...@gmail.com>
> ...
>
> read more »

Juan Pablo Gardella

unread,
Apr 6, 2011, 10:25:16 AM4/6/11
to google-we...@googlegroups.com
If is a GAE application, I think that you can't use SQL database, but I don't know GAE-

2011/4/6 Jose Luis Hernandez <jose.her...@gmail.com>
It is an application, but in future it should be integrated into OSGi,
> ...
>
> read more »

Jose Luis Hernandez

unread,
Apr 6, 2011, 10:39:02 AM4/6/11
to Google Web Toolkit
Also, I am trying to access via HSQLDB. My class is:
public class ManejadorBD {
public boolean checkUser(String user, String pass) throws
Exception{
Class.forName("org.hsqldb.jdbcDriver");
Properties prop = new Properties();
prop.load(this.getClass().getResource("database.properties").openStream());
JDBCDriver driver = new JDBCDriver();
Connection conn = driver.connect("jdbc:postgresql://
localhost:
5432/3encult", prop);
String sql = "SELECT login,password FROM \"user\"";
Statement statement = (JDBCStatement)
conn.createStatement();
ResultSet tabla = statement.executeQuery(sql);
while(tabla.next()){
if(user == tabla.getString("login") && pass
==
tabla.getString("password")) return true;
else return false;
}
}
}

And the properties file is:
user=3encult
password=3encult

I read ctbe properties file and I can obtain the user and password,
but when I want to connect to database I obtain null. On API Webpage
is said that properties file at least should be contain user and
password. Also I call to acceptsURL method with the URL of database
and it is returned true. Then, the connection to URL can be
established, but the properties are not loaded. The user and pass are
OK! I have created the user on database.

http://hsqldb.sourceforge.net/doc/2.0/apidocs/org/hsqldb/jdbc/JDBCDriver.html#connect(java.lang.String,
java.util.Properties)
http://hsqldb.sourceforge.net/doc/2.0/apidocs/org/hsqldb/jdbc/JDBCDriver.html#acceptsURL(java.lang.String)

On Apr 6, 4:25 pm, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> If is a GAE application, I think that you can't use SQL database, but I
> don't know GAE-
>
> 2011/4/6 Jose Luis Hernandez <jose.hernande...@gmail.com>
> ...
>
> read more »

Ed

unread,
Apr 6, 2011, 12:00:33 PM4/6/11
to google-we...@googlegroups.com
dont think you can mix hssqldb and postgres drivers

A. Stevko

unread,
Apr 6, 2011, 1:35:44 PM4/6/11
to google-we...@googlegroups.com
Turn off App Engine in the project properties and run your servlets on your own tomcat/java server.
The App Engine servlet context has restricted java apis like Socket and jdbc.
If you want to use GAE, check out objectify-appengine for a simple way to store your data.
If not, then google "GWT external server jboss" for approaches to rolling your own.
--
-- A. Stevko
===========
"If everything seems under control, you're just not going fast enough." M. Andretti





Reply all
Reply to author
Forward
0 new messages