javapostgresqlgwtgwt-rpcweb-container

GWT + Postgres tutorial


I need to connect my backend in Postgres with GWT, but I am not able to find any suitable tutorial.

Also I have read that I need some kind of web container to do that, but I don't know how?

If anyone could help me with how the connection needs to be created between postgres and GWT and how do I use RPC and the web container that would be great!

A step-by-step answer would really help me understand the basic approach.

I am using Eclipse to code.

Thanks!


Solution

  • On the server side in GWT you can work with connection to DataBase as in any other project is not based on the GWT. To do this you can simply use the JDBC driver & use the "Connection" object. For example:

    PreparedStatement ps = null;
    ResultSet resultSet = null;
    ps = connection.prepareStatement("Select * from Users Us");
    resultSet = ps.executeQuery();
    while (resultSet.next()) {
        //take the field and do something with it. You can take something with construction "resultSet.getInt("Us.id")"
    }
    

    If you want to transfer objects , that reflect entity of the database, through RPC to client side, they must implement the interface "Serializable". To work with database objects, you can also use the ORM-systems, such as Hibernate.