Discussion Board

Page 1 of 11 12345678910 ... LastLast
Results 1 to 15 of 162
  1. #1
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    Greetings

    I'm trying to connect my WebApplication(I'm using Apache Tomcat + NetBeans) to an external MySQL database(i.e.: that which exists on the same PC but was not created by this application).
    I then need to move on to making sure my MobileApplication is able to access this db. All I need to do is view the data(read), and not write or create anything.

    I have the code from a book: Professional Java Mobile Programming. I need some help modifying that code, I think I need the correct link/path-which I think should include the IP address of my PC..?

    Please help

  2. #2
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,903
    which I think should include the IP address of my PC..?
    IP address as localhost should also work, along with port no. on which Apache Tomcat is running.

    thanks,
    ~Amitabh

  3. #3
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    below is the function read() which is called by the servlet..when i run the midlet, it prints a1 only, and then goes to the last catch block, displaying "Error: IO Exception", in the emulator.
    This code was originally supposed to work with a db created by this application, however I'm trying to modify it so I can use it with my MySQL db-which has already been created on this machine. Do I need the path for where MySQL is stored or something? Please have a look at the method below:

    //http connection is opened using url typed into the texbox
    public final static String read(String url){
    String result = null;
    HttpConnection hc = null;
    InputStream is = null;
    try{System.out.println("a1");//
    hc = (HttpConnection) Connector.open(url);
    System.out.println("a2");//
    hc.setRequestMethod(HttpConnection.GET);
    String profiles = System.getProperty("microedition.profiles");
    String configuration = System.getProperty("microedition.configuration");
    hc.setRequestProperty("User-Agent", "Profile/" + profiles + "Configuration/" + configuration);
    String locale = System.getProperty("microedition.locale");
    if (locale != null){
    hc.setRequestProperty("Content-Language", locale);
    }//if
    String platform = System.getProperty("microedition.platform");
    if(platform != null){
    hc.setRequestProperty("J2ME-Platform", platform);
    }
    try{
    if (hc.getResponseCode() == HttpConnection.HTTP_OK){
    System.out.println("x1");//
    is = hc.openInputStream();
    InputStreamReader isReader = new InputStreamReader(is);
    int len = (int) hc.getLength();
    if (len > 0){System.out.println("x2");//
    char[] chars = new char[len];
    int actual = isReader.read(chars);
    result = new String(chars);
    }else{System.out.println("x3");//
    StringBuffer sb = new StringBuffer();
    int ch;
    while ((ch = is.read()) != -1){System.out.println("x4");//
    sb.append((char) ch);
    }
    result = sb.toString();
    }
    }else{System.out.println("x5");//
    result = "Error: return code was " + hc.getResponseCode();
    }
    }catch (IOException e){
    result = "Error: is the web server running?";
    }finally{
    if(is != null){
    is.close();
    }
    if(hc != null){
    hc.close();
    }
    }//finally
    }catch (IOException ioe){
    result = "Error: IO exception.";
    }

    return result;
    }//read()

  4. #4
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,903
    Add some more SOP's to see on which line you are getting the exception ?

    thanks,
    ~Amitabh

  5. #5
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    it's not printing a1,x1,x2,x3,x4, or x5, meaning it's not even connecting to the db
    (i.e. it enters the first try block, but does not connect-lines 1,2,and 3 in the 1st try block)

  6. #6
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,903
    The check the server URL in the browser is it working ?

    In perivous email you wrote "when i run the midlet, it prints a1 only"

    thanks,
    ~Amitabh

  7. #7
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    SOP "a1" Should be printed,check
    Can you share the URL that you are calling.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  8. #8
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    sorry a1 is printed

    it's a2 and the rest which are not

    the url I'm using is: (private final static String URL =) "jdbc:mysql://:3306/db_audiology?";

  9. #9
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    when i run: "http://localhost:8080/" in the browser, it runs
    but MySQL url doesn't

  10. #10
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    Is this url-> jdbc:mysql://:3306/db_audiology? is passed to the Connection.open("");
    Next to the a1 SOP
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  11. #11
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    yes it is

  12. #12
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    when I pass http://localhost:8080 in the following stmt: hc = (HttpConnection) Connector.open(url);
    it prints a1, a2 and the midlet reads: "Error: is the web server running?"

  13. #13
    Nokia Developer Champion im2amit's Avatar
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    2,903
    Quote Originally Posted by hm991 View Post
    sorry a1 is printed

    it's a2 and the rest which are not

    the url I'm using is: (private final static String URL =) "jdbc:mysql://:3306/db_audiology?";
    You can only open HTTP Connection not jdbc connection from your midlet.

    For your need, you have to run a server side script say .JSP (example getData.jsp) which connects to mysql database using JDBC and then gives the needed data to mobile client.

    this url can be --> http://localhost:8080/getData.jsp



    thanks,
    ~Amitabh

  14. #14
    Regular Contributor hm991's Avatar
    Join Date
    Mar 2010
    Posts
    108
    Thanks a lot!

    I'll use a PHP script as I have no experience in JSP

  15. #15
    Nokia Developer Champion raj_J2ME's Avatar
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,314
    Quote Originally Posted by hm991 View Post
    when I pass http://localhost:8080 in the following stmt: hc = (HttpConnection) Connector.open(url);
    it prints a1, a2 and the midlet reads: "Error: is the web server running?"
    Hello,
    If you go through the GCF framework then you will find that the Connector.open() can be used for the protocols like, http, socket, datagram.You use Connector.open as in the next code fragment, supplying a single String parameter that specifies a protocol, an address, and parameters:
    For example,
    * HTTP Connection: Connector.open("http://java.sun.com/wireless")
    * Socket Connection: Connector.open("socket://java.sun.comort")
    * Datagram Connection: Connector.open("datagram://java.sun.comort")

    and other than these you can open the File Connection.And that's all.

    Therefore you are passing the wrong URL.
    Attached Images Attached Images
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Page 1 of 11 12345678910 ... LastLast

Similar Threads

  1. Replies: 1
    Last Post: 2010-04-01, 05:20
  2. can't load MySql driver
    By mani_lachi in forum [Archived] Qt SDKs and Tools
    Replies: 7
    Last Post: 2009-12-17, 09:28
  3. Problem using MySQL on s60 3rd
    By DFurió in forum Mobile Web Server
    Replies: 14
    Last Post: 2008-12-11, 08:58
  4. MySQL on pamp
    By stevenmartin99 in forum Mobile Web Server
    Replies: 0
    Last Post: 2008-02-03, 19:52
  5. JDBC & MySQL problems
    By cyntellitek in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-10, 01:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved