aspose file tools*
The moose likes GWT and the fly likes Help please with GWT Sql Connection ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Help please with GWT Sql Connection ... " Watch "Help please with GWT Sql Connection ... " New topic
Author

Help please with GWT Sql Connection ...

Valex World
Greenhorn

Joined: Jan 23, 2011
Posts: 3

Sorry for my bad english !

Hello, I'm new in java tehnologies ... I begin to study java GWT tehnology , help me please how to make connection to my sql server in my gwt application ... I don't know what to utilise Ecliplse or Netbeans ( i know that in eclipse existing gwt designer and i can very easy set to my gwt elements beatiful font , but i can not make connection to my sql server ... i read on the diverse forums that in eclipse with appengine cannot to connect sql database , in don't know it's true or not )
Give me please a little example how i can do it ! don't interesting eclipse or netbeans ... i need to do a project but i have a little time ...



Thanks !!!

P.S
please if you can send source code project to :
my skype - grindays
yahoo ID sarbustean@yahoo.com
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Welcome!

GWT Java code is compiled to JavaScript. The result runs in the client's browser. It can't create an SQL connection.

You need some server-side component that does this and some means of communication between the two. The server-side component can be anything, like a PHP application, a Ruby on Rails application or some Java application. The communication between client and server can be easy when you use Java; GWT comes with a custom RPC servlet that lets you send Java objects back and forth between client and server. If your server faciliates some other language/basis, a good way to choose would be REST with XML or JSon. (In fact it may even be a good idea when your server is Java based.)

On the server side you use the framework's or language's capabilities for SQL databse access as usual.
Valex World
Greenhorn

Joined: Jan 23, 2011
Posts: 3

Hauke Ingmar Schmidt wrote:Welcome!

GWT Java code is compiled to JavaScript. The result runs in the client's browser. It can't create an SQL connection.

You need some server-side component that does this and some means of communication between the two. The server-side component can be anything, like a PHP application, a Ruby on Rails application or some Java application. The communication between client and server can be easy when you use Java; GWT comes with a custom RPC servlet that lets you send Java objects back and forth between client and server. If your server faciliates some other language/basis, a good way to choose would be REST with XML or JSon. (In fact it may even be a good idea when your server is Java based.)

On the server side you use the framework's or language's capabilities for SQL databse access as usual.



Thanks for you reply !!!
I know that , i read about this ... but you can give me an little exemple with Rpc way ? if you can to create a project where you make this connect ... i lose 5 days ... and i don't solve my problem ... can you help ?
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Valex Id wrote:
Thanks for you reply !!!
I know that , i read about this ... but you can give me an little exemple with Rpc way ? if you can to create a project where you make this connect ... i lose 5 days ... and i don't solve my problem ... can you help ?


I can try to help.

But I don't even know your prerequisites. How does your server side look like?

For an introduction into GWT-RPC take a look here.
Valex World
Greenhorn

Joined: Jan 23, 2011
Posts: 3

Hauke Ingmar Schmidt wrote:
Valex Id wrote:
Thanks for you reply !!!
I know that , i read about this ... but you can give me an little exemple with Rpc way ? if you can to create a project where you make this connect ... i lose 5 days ... and i don't solve my problem ... can you help ?


I can try to help.

But I don't even know your prerequisites. How does your server side look like?

For an introduction into GWT-RPC take a look here.



I have local MySql server, I'm using Netbeans(with Tomcat ) and Eclipse ( in Eclipse i'm using appengine web server, I dont know how to set Tomcat for GWT applications... ) . If you can show me an example where you connect to the Mysql server with RPC, then I will set my sql parametres and try to connect to my server ....

Thanks ... !


Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Valex Id wrote:


Please check your private messages for an important administrative matter.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Valex Id wrote:
I have local MySql server, I'm using Netbeans(with Tomcat ) and Eclipse ( in Eclipse i'm using appengine web server, I dont know how to set Tomcat for GWT applications... ) . If you can show me an example where you connect to the Mysql server with RPC, then I will set my sql parametres and try to connect to my server ....

Thanks ... !




Since you already have eclipse, I would suggest following the GWT-RPC tutorial Hauke already provided. With the eclipse plugin, you can get a read made, ready to run project.
Once you achieve this, you will notice the server side class which you need to focus on is the xxxImpl.
Do you know how to write code which will open a connection and interact with the DB? If not you can start here http://www.coderanch.com/how-to/java/JdbcFaq

Essentially, you will need a class which talks to the DB.
This class should provide convenient methods to access the DB data.
From your xxxImpl you will need to invoke these methods and return the serialized data to the client.

In your original post you mentioned GAE. It is true, if you host your application to the gae jpa. However, you can always host your GWT app on tomcat and connect to the DB of your choice
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Maneesh Godbole wrote:In your original post you mentioned GAE.


Oh. I am sorry, you did.

It is true, if you host your application to the gae jpa. However, you can always host your GWT app on tomcat and connect to the DB of your choice


Maneesh is right, with GAE you can't use a SQL database. The provided datastore (BigTable) is different to SQL in some important aspects and needs different approaches; the JPA and JDO interfaces can't hide this (and they are not the best fit, especially JPA was made with a relational model in mind).

Sorry for misleading you a bit.

With GAE the setup is easy, an example RPC is provided, tutorials for data access "the GAE way" are provided at the GAE site. But no easy SQL integration there.

But whether you use GAE or not, this has not much to do with GWT. You can't use every feature of every persistence framework when sending objects to the GWT client, e.g. lazy loading will break. So you need to take care of what you send.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Hauke Ingmar Schmidt wrote:
.... You can't use every feature of every persistence framework when sending objects to the GWT client, e.g. lazy loading will break. So you need to take care of what you send.


I am not sure I understand you clearly here.
Ideally the persistence mechanism should be transparent to the client. As long as the client performs its data communication with the server, using serialized POJOs which can be translated to JS, all should be smooth sailing.
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Maneesh Godbole wrote:
Hauke Ingmar Schmidt wrote:
.... You can't use every feature of every persistence framework when sending objects to the GWT client, e.g. lazy loading will break. So you need to take care of what you send.


I am not sure I understand you clearly here.
Ideally the persistence mechanism should be transparent to the client. As long as the client performs its data communication with the server, using serialized POJOs which can be translated to JS, all should be smooth sailing.


If you use lazy loading e.g. in Hibernate, you don't get the POJOs but proxies with references to the entity manager and session. Dependent data (references) will not be fetched when the original object is constructed but at first access. This works fine with server-side frameworks, but does break with GWT.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Oh! My bad. I mentally blocked myself into thinking GWT LazyPanel while reading about lazy loading! Duh!

Yes you are correct. However, this is one of the possible workarounds http://hibernate4gwt.sourceforge.net/hibernate_gwt_lazy_issue.html
 
wood burning stoves
 
subject: Help please with GWT Sql Connection ...