Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By Eranga

Thread: Connect to data base in J2ME

  1. #1
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Post Connect to data base in J2ME

    Hello,
    I have a prọect need use data base in server. How can I do connect to data base when open my project and display data of it.
    I understand I need create a void connect for app, and get content of that data base for compare, display, or other choice.
    But I don't know how getting a content and display in mobile. I not understand about servlets, a people will programming web by php, and I need connect it on mobile with my app.
    Please, anybody help me.
    Thanks!

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    First of all, show us your attempt here. What you've done so far. It dosen't matter you've done something right or wrong, but your effort it more important.

    The next thing is before done any project in any language, try to come up with a proper design. Don't change a lot at the middle, minor changes could be. Looking at your question seems to me you are lost with different technologies, isn't it?
    pavankumarragi likes this.

  3. #3
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Yes, my mind is I create a project can get content data of a website.
    But I don't understand how getting it, and application using now (snaptu,...) what used method for display information on screen. Are they connect with servlets or connect direct with data base?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    JSP, Servelets, etc are technologies to build web applications in Java, in simple word. If you are consider a web side the backend done all the data processing, and all your database related stuff done there. You have to create database connection and query data from there.

  5. #5
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Thank you!

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Your are welcome. :)

    So what you going to do? What's your approach? Is everything clear to you?

  7. #7
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    I will open a connect http, and get ID of content I want display, I writing code.
    But I don't know can running my app. :D

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  9. #9
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Yes, Ok!
    Now, I have a problem with TextFiedl, I have:
    user = new TextField("E-Mail:", "", 100, TextField.ANY);
    pass = new TextField("Pass word:", "", 16, TextField.PASSWORD);
    I get valuue of TextField with String testUser = user.getString(); and I send to gateway.
    This, I want input is email (ex: abc@yahoo.com) and pass, then I send email for gateway by sms, but when tester input email and sending, device appear error application:
    " Illegal State: java/lang/IllegalStateException".
    How can I fix this error? This error appear when running application on mobile. (N6280).
    Help me!
    Thanks

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  11. #11
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Yes, That error complete.

  12. #12
    HoangNgoc is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    public void TestValue(TextField value){
    this.user = value;
    if ((user.getString().equals("")))
    {
    error.setTimeout(Alert.FOREVER);
    Display.getDisplay(this).setCurrent(error, mF3);
    I think in this code I do not throws Exception for message, I want check value of TextField, nad if value = null, display Alert.
    I call void check username when user button "Next", and IllegalStateException appear here. Maybe I write code not true when check username, I read about IllegalException so I thinking.
    This my MIDlet:
    import javax.microedition.midlet.*;
    import VsaoLib.DangkyTV;
    import java.util.*;
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;

    /**
    * @author Kien
    */
    public class Vsao extends MIDlet implements CommandListener {
    private DangkyTV newDK1, newDK2, newDK3;
    private Command mDangky, mDangnhap, mBack, mNext, mOk, mExit, mChoice;
    private Form mF1, mF2, mF3, mF4;
    private String tb1, tb2;
    private TextField user, pass;
    private Alert error;
    private String url, testUser, testPass;

    public Vsao(){
    user = new TextField("E-Mail:", "", 100, TextField.ANY);
    pass = new TextField("Pass word:", "", 16, TextField.PASSWORD);
    tb1 = new String("Chao mung ban den voi Vsao");
    error = new Alert("Dang ky khong dung", "Hay nhap dung dia chi email va"
    + " pass word", null, AlertType.ERROR);
    mDangky = new Command("Dang ky", Command.SCREEN, 1);
    mDangnhap = new Command("Dang nhap", Command.SCREEN, 1);
    mBack = new Command("Quay lai", Command.BACK, 1);
    mOk = new Command("Hoan thanh", Command.OK, 0);
    mExit = new Command("Thoat ra", Command.EXIT, 1);
    mNext = new Command("Tiep tuc", Command.SCREEN, 1);
    mChoice = new Command("Lua chon", Command.OK, 1);
    testUser = user.getString();
    testPass = pass.getString();
    }
    public void startApp() {
    mF1 = new Form("Vsao xin chao");
    mF1.append(tb1);
    mF1.addCommand(mDangky);
    mF1.addCommand(mDangnhap);
    mF1.setCommandListener(this);
    Display.getDisplay(this).setCurrent(mF1);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void closeApp(){
    /*
    * Kiem tra che do app dang chay, neu con truy cap thi dong truy cap
    * sau do tien hanh dong app
    */
    destroyApp(true);
    notifyDestroyed();

    }

    public void commandAction(Command c, Displayable d){
    if (c == mDangky) {
    newDK1 = new DangkyTV("Dang Ky"); //tin nhan 1
    newDK1.send("DK1", "8047");
    HienthiMF3();//form dang ky user
    }
    else if (c == mNext)
    {
    TestValue(user);
    }
    else if (c == mOk) {
    TestPass(pass);
    HienthiMF2();//Display Mf2
    }
    else if (c == mBack){
    HienthiMF2();
    }else if(c == mDangnhap){
    HienthiMF2();//Display mF2
    }
    else if(c == mExit){
    closeApp();
    }
    }

    public void TestValue(TextField value){
    this.user = value;
    if ((user.getString().equals("")))//phai bat ngoai le cho message
    {
    error.setTimeout(Alert.FOREVER);
    Display.getDisplay(this).setCurrent(error, mF3);
    } else{
    SendUser();//send message with username = value of TextField
    HienthiMF4();
    }
    TestValue(value);
    }

    public void TestPass(TextField pass1){
    this.pass = pass1;
    if (pass.getString().equals("")){
    Display.getDisplay(this).setCurrent(error, mF4);
    } else{
    SendPass();//send message with pass = value of TextField
    }
    //TestPass(pass1);
    }

    public void HienthiMF3(){//Display MF3
    mF3 = new Form("Dang Ky Thanh Vien");
    mF3.append(user);
    mF3.addCommand(mNext);
    mF3.addCommand(mBack);
    mF3.setCommandListener(this);
    Display.getDisplay(this).setCurrent(mF3); //hien thi man hinh chính mF1
    }

    public void HienthiMF4(){//Display MF4
    mF4 = new Form("Dang Ky Thanh Vien");
    mF4.append(pass);
    mF4.addCommand(mOk);
    mF4.addCommand(mBack);
    mF4.setCommandListener(this);
    Display.getDisplay(this).setCurrent(mF4);
    }

    public void HienthiMF2(){
    mF2 = new Form("Chao mung ban da den voi Vsao");
    mF2.addCommand(mExit);
    mF2.addCommand(mChoice);
    mF2.setCommandListener(this);
    //mF2 ket noi toi Wap
    Display.getDisplay(this).setCurrent(mF2);
    }

    public void SendUser(){//send Message to gateway
    newDK2 = new DangkyTV("User name");
    newDK2.send(testUser, "8047");
    }
    public void SendPass(){
    newDK3 = new DangkyTV("pass"); //DangkyTV extends Sender class
    newDK3.send(testPass, "8047");
    }

    }
    I don't understand my Error, please help me, Thanks!

Similar Threads

  1. Getting problem inserting data in data base
    By anupama in forum New To Java
    Replies: 4
    Last Post: 12-15-2010, 10:03 PM
  2. data structure and data base??
    By ahmed13 in forum Advanced Java
    Replies: 8
    Last Post: 03-27-2009, 05:48 AM
  3. how to store the data in data base
    By eclipse3.4ide in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 04:25 AM
  4. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 04:10 PM
  5. Replies: 1
    Last Post: 08-06-2007, 05:38 PM

Posting Permissions

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