×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 28
  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    54

    [moved] How to connect database located on webhost?

    I am developing an app for java phone and have created a database on webhost!!! what is the way or code to connect database on the web host?

    Plzz help me asap!!
    Thanks in advance!!!
    Vinita

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to connect database located on webhost?

    I would suggest designing it in a way that clients would only need to use HTTP queries, and all logic would be on the server side.

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    54

    Re: How to connect database located on webhost?

    Quote Originally Posted by symbianyucca View Post
    I would suggest designing it in a way that clients would only need to use HTTP queries, and all logic would be on the server side.
    import java.io.*;
    import java.util.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;

    public class MySQLConn extends MIDlet implements CommandListener {
    private String username;
    private String url = "http://mysql3.000webhost.com/a4740680_user";
    private Display display;
    private Command exit = new Command("EXIT", Command.EXIT, 1);;
    private Command connect = new Command("Connect", Command.SCREEN, 1);
    private TextField tb;
    private Form menu;
    private TextField tb1;
    private TextField tb2;
    DBConn db;

    public MySQLConn() throws Exception {
    display = Display.getDisplay(this);

    }

    public void startApp() {
    displayMenu();
    }

    public void displayMenu() {
    menu = new Form("Connect");
    tb = new TextField("Please input database: ","",30,TextField.ANY );

    tb1 = new TextField("Please input username: ","",30,TextField.ANY);

    tb2 = new TextField("Please input password: ","",30,TextField.PASSWORD);

    menu.append(tb);
    menu.append(tb1);
    menu.append(tb2);
    menu.addCommand(exit);
    menu.addCommand(connect);
    menu.setCommandListener(this);
    display.setCurrent(menu);
    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void commandAction(Command command, Displayable screen) {
    if (command == exit) {
    destroyApp(false);
    notifyDestroyed();
    } else if (command == connect) {
    System.out.println("1");
    db = new DBConn(this);
    System.out.println("2");
    db.start();
    System.out.println("3");
    db.connectDb(tb.getString(),tb1.getString(),tb2.getString());

    System.out.println("Connected");
    }
    }

    public class DBConn implements Runnable {
    MySQLConn midlet;
    private Display display;
    String db;
    String user;
    String pwd;
    public DBConn(MySQLConn midlet) {
    this.midlet = midlet;
    display = Display.getDisplay(midlet);
    }

    public void start() {
    Thread t = new Thread(this);
    t.start();
    }

    public void run() {
    StringBuffer sb = new StringBuffer();
    try {
    HttpConnection c = (HttpConnection) Connector.open(url);
    c.setRequestProperty("User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");
    c.setRequestProperty("Content-Language","en-US");
    c.setRequestMethod(HttpConnection.POST);
    DataOutputStream os = (DataOutputStream)c.openDataOutputStream();

    os.writeUTF(db.trim());
    os.writeUTF(user.trim());
    os.writeUTF(pwd.trim());
    os.flush();
    os.close();

    // Get the response from the servlet page.
    DataInputStream is =(DataInputStream)c.openDataInputStream();
    //is = c.openInputStream();
    int ch;
    sb = new StringBuffer();
    while ((ch = is.read()) != -1) {
    sb.append((char)ch);
    }
    showAlert(sb.toString());
    is.close();
    c.close();
    } catch (Exception e) {
    showAlert(e.getMessage());
    }
    }
    /* This method takes input from user like db,user and pwd and pass to servlet */
    public void connectDb(String db,String user,String pwd) {
    this.db = db;
    this.user = user;
    this.pwd = pwd;
    }

    /* Display Error On screen*/
    private void showAlert(String err) {
    Alert a = new Alert("");
    a.setString(err);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    }
    };
    }

    i tried this code but the it is not connecting to my database on webhost!!! n this code is error free!!!
    but i dunno how can i check whether the connection is successful


    Thanks Vinita

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to connect database located on webhost?

    java questions should be asked under the java section.

    Anyway, do debug on what happens on your device side, and verify that all code executes as planned, then do the same in web code side, and then when you have isolated the actual problem, then ask for more help. And please do it under the selected technology area in this discussion baord.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    21

    How to Insert Data into database created on webhost server in javame

    hi, I have created a mysql database on free webhost server i am getting connection to that webhost server through netbeans javame but i am not getting how to insert or retrieve data from the mysql database which is located at free webhost server throgh javame.....

    plzz help

    thanks \
    swati!!

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    21

    Re: How to connect database located on webhost?

    i can come to know only when i can insert data in the database on web host server... but in java me i am not getting code for how i can insert data in database created on web host server!!!

    Plzzz help it is really very urgent!!!

    Thnks

  7. #7
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to connect database located on webhost?

    Do check what I did suggest. Basically just make the logic in web server to accespt data over HTTP Get/POST, and have all logic for data handling in there.

    Then in client side, simply make HTTP query, nothing else is really needed.

  8. #8
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to Insert Data into database created on webhost server in javame

    I would suggest using the HTTP fro client side, and having the whole database logic handled in webserver, as explained in your other thread: http://www.developer.nokia.com/Commu...ted-on-webhost

    anyway, lets see if our Champions or any other valuable members would have better suggestions.

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: How to Insert Data into database created on webhost server in javame

    The threads are merged now. And it is really up to you how you enable remote access to your database, and providing a HTTP/HTTPS service would be a good direction.
    Here are the connectors you could use, http://dev.mysql.com/doc/index-connectors.html, their availability depends on the actual server/host of course.

  10. #10
    Registered User
    Join Date
    Jan 2013
    Posts
    54

    Re: How to Insert Data into database created on webhost server in javame

    Sir actually m still stuck and not actually getting what should be done. we cannot difrectly insert data into our database we have to use web services. But now i have created an online server on 000webhost server n found that the only way to insert data is through PHP. but i am totally unknown to this language, n i tried some tutorial of PHP but even the localhost is not getting connect. what is the way i can insert data into my database through PHP file.

    Plzz help .... asap

    Thanks Vinita!!!

  11. #11
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to Insert Data into database created on webhost server in javame

    As here we are not really conentrating on PHP or ny other server side technology not related to Nokia services, I would suggest that you would try finding a discussion board that does that. Basically I would feel that, by doing so, you would be receiving best sutable support. Here' we generally do know best the client seide, at least when it is cencerning application & service development for Nokia devices & services.

  12. #12
    Registered User
    Join Date
    Jan 2013
    Posts
    54

    Re: How to Insert Data into database created on webhost server in javame

    @symbianyucca : m successfully done with my server part but now i have to send a permission request to my friend asking permission whether i can track his/her or not in java me!!!
    I m not having any idea about how can i implement such!!! Is it like i have to send message? but it is becoming really a very big module for me ... can u suggest some alternative!!!
    Plzz help....

    Thanks
    Vinita!!!

  13. #13
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: How to Insert Data into database created on webhost server in javame

    Not getting the problem really. What do you mean by permission request to my friend asking permission whether i can track his/her or not ?

    Anyway, if it is about the dialogs shown in phone, then you could get rid of them only by signing the app. Not reallyu an expert on the topic, anyway, you could check what our wiki has on the topic, and start in: http://www.developer.nokia.com/Commu...ng_for_dummies

  14. #14
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,684

    Re: How to Insert Data into database created on webhost server in javame

    You could store tracking requests on the server, and ask for them in the client when it is sending data (so it is communicating with the server anyway). Then display the question and send back the result.

  15. #15
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429

    Re: How to Insert Data into database created on webhost server in javame

    You need to consider : Whether you have to do the location tracking request once (and available later in settings of the app) or for each friend you add.

    If its only once, its easy and you can add it as a check box while registering the app. Else each time you add a friend, there should be a check box or an alert to confirm location sharing.

    Regards
    Gopal

Similar Threads

  1. how to connect the remote database
    By ragu. in forum Symbian
    Replies: 1
    Last Post: 2011-01-08, 09:40
  2. How to connect with the database using the xhtml MP or WAP?
    By kpvrlakshmi in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2009-11-10, 14:09
  3. How to connect with database
    By sulabh120881 in forum Symbian
    Replies: 14
    Last Post: 2007-08-31, 14:54
  4. Connect MySQL Database
    By ernestkok in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2004-03-22, 09:23

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×