facebook

Database access from mobile device

  1. MyEclipse IDE
  2.  > 
  3. Mobile Tooling
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #350834 Reply

    Zack
    Member

    I have developed a asp.net web application with two way access to MSSQL server database on webserver. I need to provide mobile access providing similar functionality. I have done my research and decided that MyEclipse will be best suited for this. I am however totally new in this space always being in a .net environment. I am very willing to learn and to put in the hours but would really appreciate some advise and pointers to get started. Up to this point I can do menus, buttons, text boxes, etc. Need advise to update SQL with captured data from textboxes, read data from SQL and display on mobile and lastly upload captured images to a destination on the server. All of this is currently working in my ASP.NET app so I understand the concepts and approach. Would appreciate your help of ‘going mobile’ 🙂
    regards

    #350951 Reply

    Brian Fernandes
    Moderator

    Harties,

    Unsure how we missed your post, sorry for the very delayed response.

    The easiest way to access data would be writing a REST client (something that can pull data from REST web services) in your mobile application, this is easy to do with JS (and there are libraries which will help).

    For the backend, are you writing that in Java / JEE? You would use JPA to access the data from the database and then use REST web services to expose the data (which in turn is used by your client).

    I know this is a bit high level, but unsure if this is the information you are looking for (or if you already found a way to achieve this).

    Do let us know if you need more assistance.

    #350966 Reply

    Lofi
    Participant

    @Harties wrote:

    I am very willing to learn and to put in the hours but would really appreciate some advise and pointers to get started.

    This is how you’d do it with MyEclipse 2015, JBoss 7 and Java 7:

    * create a dynamic web project, e. g. MyServer

    * create these classes in /src:

    JaxRsActivator.java:

    
    import javax.ws.rs.ApplicationPath;
    import javax.ws.rs.core.Application;
    
    @ApplicationPath("/")
    public class JaxRsActivator extends Application {
     
    }
    

    MyService.java

    
    
    import java.io.Serializable;
    
    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import javax.servlet.http.HttpServletResponse;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.MediaType;
    
    @Stateless
    @LocalBean
    @Path("/")
    public class MyService {
    
        @GET
        @Path("/hello/{name}")
        @Produces( MediaType.APPLICATION_JSON)
        public Hello hello(@Context HttpServletResponse servlrsp, @PathParam("name")String name){
    
            return new Hello( name);
        }
    
    
        private class Hello implements Serializable {
            
            private String name;
            
            public Hello( String name) {
                this.name = name;
            }
    
            public String getName() {
                return name;
            }
    
            public void setName(String name) {
                this.name = name;
            }
            
        }
    }
    

    add a /MyServer/WebRoot/WEB-INF/jboss-web.xml:

    
    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web>
        <context-root>myservice</context-root>
    </jboss-web>
    

    * start JBoss. Now you can use the service, e. g.

    http://localhost:8080/myservice/hello/world

    would return

    
    {"name":"world"}
    

    * create your html page, e. g.:

    
    <!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    
        <div>
            Message from server: <div id="response"></div>
        </diV>
    
        <script>
            var xhr = new XMLHttpRequest();
            xhr.open('GET', 'http://localhost:8080/myservice/hello/world');
            xhr.onload = function(e) {
                var data = JSON.parse(this.response);
                document.getElementById("response").innerHTML = data.name;
            };
            xhr.send();
        </script>
    
    </body>
    </html>
    

    I prefer jQuery and jQuery Mobile though. You really should look into it.

    Invoking the page will get you:

    Message from server:
    world
    

    That’s very quick and dirty, but it’s the necessary stuff.

    Have fun! 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Database access from mobile device

You must be logged in to post in the forum log in