GWT phoneGap Database connectivity

232 views Asked by At

I've been developing GWT applications for some time , This is my first time creating an app in GWT/Phonegap with mgwt.

I just migrated my old GWT project to phoneGap ,everything's fine , i can see my running GWT app on mobile.In my GWT website , I was using MySQL,Hibernate

Now I'm confused what i need to get connected my this Mobile App to a database. Can i use the same sql, hibernate..

Or i need something else, and writing all the queries again for mobile?

I found this during my search ..do i need to use this one..

https://code.google.com/p/gwt-localstorage-db/wiki/UsingTheApi


I was connecting to db in my gwt web app like this in my applicationcontext.xml class

             <?xml version="1.0" encoding="UTF-8"?>

     <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"
default-lazy-init="true">

<!-- Datasource for LOCAL database connection -->

<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost/leave" />
    <property name="username" value="root" />
    <property name="password" value="" />

</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.leavemanagement.shared.User</value>


        </list>
    </property>
</bean>
<bean id="ManagerExams" class="com.leavemanagement.database.MySQLRdbHelper">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

2

There are 2 answers

2
AudioBubble On

@junaidp,
I don't know what GWT is. Java beans are not available via phonegap, but Java code can be added via plugins. You can create private plugins.

For your task, you need to use a plugin to access your DB. This is your search link for plugins. You will want to use "localstorage" for simple storage. For more complex storage on the device you have "indexDB" and "sqlite". If you need more storage, use on-line (internet) storage via a REST API - like parse.com or firebase.com.
-Jesse

0
AudioBubble On

@junaidp Wait... I think you are saying that you are the creator/developer/programmer behind GWT for phonegap. Let me assume that for a moment. If so, my original advice does NOT change. However, you are asking for connectivity architecture. There is a dozen ways to do this. At minimum you'll need these pieces.

  1. A plugin that runs on phonegap. It has a Javascript interface, then native code that use the network available to it to send data to the server.
  2. A CGI or equivalent on the server. However, the modern approach is to use a REST Interface.
  3. The connect between the two would likely use JQuery or some other AJAX technology. The transport could also be Websocket, but that has overhead issues.

Another design item is security. It would be best not to run any SQL scripts from the mobile device, otherwise this would be subject SQL-injection attacks

If you need anything else, this is the wrong forum. I suggest moving this discussion to Google Groups for Phonegap.