Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2004, 03:35 PM
vishalneo vishalneo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: mauritius
Posts: 9 vishalneo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 17 sec
Reputation Power: 0
accessing database from midlets n returning many records

hi,
Finally i solved my previous problem on my own.
Now i want to know how to connect to a database and retrieve many records and display on a mobile, using j2me.

bye.

Reply With Quote
  #2  
Old January 13th, 2004, 09:03 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Hi Vishalneo,

This is another topic of great interest.... Especially those who first get into J2ME... I also thought the same: query the DB right from within the MIDlet.

For simplicity (again, J2ME is meant to be lightweight), you should consider creating a Servlet (assuming you're using Java on the server) that connects to the database, retrieves the records, and then passes it back to the MIDlet. So rather than having the MIDlet connect to your Oracle/MySQL/Whatever database, it calls the Servlet, which then queries the database and returns to the results to the calling client (MIDlet).

Hope this helps...

Reply With Quote
  #3  
Old January 13th, 2004, 10:09 PM
vishalneo vishalneo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: mauritius
Posts: 9 vishalneo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 17 sec
Reputation Power: 0
Hi again,

Concerning the midlet problem i had earlier, resolved it. i used only 1 midlet and others are classes. My codes has become much more simpler, that's what Object 0riented progamming is I think!

The problem still exists for the database issue. I have 4 functionalities in my application. Each one has specific search parameters to pass to the database. That's where i'm stuck. have you done something like this?
If i succeed in solving for one of the functionality, i'll b able to solve the others in no time just like for the midlets and classes.

bye

Reply With Quote
  #4  
Old February 11th, 2004, 07:46 AM
ven ven is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 ven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
using classes

Hey,
Regarding using midlets as classes, does this mean you can access them within your main midlet? Please clarify. I am accessing a database for authentication, and then i want the user to view a list of other midlets to choose from. Any help would be most appreciated.
Regards,
Ven

Reply With Quote
  #5  
Old February 11th, 2004, 09:57 PM
vishalneo vishalneo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: mauritius
Posts: 9 vishalneo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 17 sec
Reputation Power: 0
midlet n classes

Hi,

The answer is yes. This is what OO programming is!
You create only one midlet and many classes. Inside the midlet you have to instantiate the classes.

Ex. if i have a class SearchEntity, inside the midlet i will have something like
SearchEntity SE=new SearchEntity(); //constructor
SE.anyfunction(..param); where anyfunction is a function defined in the class SearchEntity

but beware the class must not have any display declarations, ie Display.getDisplay(this)...


the anyfunction must return a Form , i.e
public Form anyfunction(){
Form frmDisplay=new Form("my class name");
frmDisplay.append("anystring");
return this.frmDisplay;
}

then in your midlet where you instantiate the class and call the anyfunction you must have

Form myForm;
myForm=SE.anyfunction();
Display.getDisplay(this).setCurrent(myForm);

as you will see, the form returned by anyfunction is 'assigned' to myForm

It is here that you must call the midlet to Display the form.
the class will not be able to display the form because it can't extend javax.microedition.midlet.*;

Hope this helps,
ask for help from morecream, i've sent him some docs

bye,
vishalneo

Reply With Quote
  #6  
Old February 17th, 2004, 06:52 AM
ven ven is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 ven User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
connecting to database

Thanks for that. Just in case you haven't solved your previoous problem, find below a snippet of code to connect to a mysql database.
HttpConnection http = null;
InputStream iStrm = null;

// Data is passed at the end of url for GET
String url = "http://localhost:8080/Params/params" + "?" +
"StudentID=" + studentID.getString() + "&" +
"pin=" + pwd.getString();
try
{

http = (HttpConnection) Connector.open(url);

http.setRequestMethod(HttpConnection.GET);
if (http.getResponseCode() == HttpConnection.HTTP_OK)
{
try
{
iStrm = http.openInputStream();
}
catch (Exception xxx)
{ System.out.println(xxx.toString());
}
int length = (int) http.getLength();
if (length > 0)
{
byte servletData[] = new byte[length];
iStrm.read(servletData);

waitForm.append("\n" + new String(servletData));
}
else
{
fmMain.append("Invalid user name or pin");
}
}

And in the servlet, the code is as follows.

public class ServletfromMIDlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
ResultSet rs = null;
String stID = req.getParameter("StudentID"),
pin = req.getParameter("pin");
if (stID == null || pin == null)
{
res.sendError(res.SC_BAD_REQUEST, "Unable to read parameters");
return;
}
Connection dbconn = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try
{
String sDBDriverClass = "com.mysql.jdbc.Driver";
String sDBConnStr = "jdbc:mysql://localhost/testdb/user=root/password=";
Class.forName( sDBDriverClass );
dbconn = DriverManager.getConnection( sDBConnStr );
if( dbconn == null )
{
throw new Exception( "Failed to get JDBC connection from DriverManager" );
}

Statement stList = dbconn.createStatement();
String sql = "";

sql = "SELECT name, surname, courseCode FROM studentDetails WHERE studentNumber = '" +stID +"' AND pin = '" +pin+"'";
ResultSet rsList = stList.executeQuery( sql );

if( rsList != null )
{
while( rsList.next() )
{
//depends on your table you are accessing
out.println( "<b>Name</b>: " + rsList.getString( "name" ) + " - <b>Surname</b>: " + rsList.getString( "surname" ) + " -<b>Course</b>: " + rsList.getString("courseCode") + "<br>" );
}
rsList.close();
}
dbconn.close();

}
catch( Exception e )
{
System.err.println( "Exception getting DB connection: " + e.toString() );
try{
if( dbconn != null ) dbconn.close();
dbconn = null;
}
catch( SQLException sqle )
{
System.err.println("Sql exception: " + sqle.toString());
}
}
}
}

Regards,
Ven.

Reply With Quote
  #7  
Old August 22nd, 2004, 10:32 PM
surreal23 surreal23 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 1 surreal23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face Can J2ME connect to Aspx Page??

I wonder instead of using servlets, can i use a aspx pageto retrieve data from the database?And may i know roughly the codes to handle the aspx page as well as the codes to put inside the midlet?

Reply With Quote
  #8  
Old August 23rd, 2004, 10:56 AM
vishalneo vishalneo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: mauritius
Posts: 9 vishalneo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 17 sec
Reputation Power: 0
my project's complete

hi frankie,

thnks 4 z help. I've already completed my project now. i will b graduating this september. but at z same time, i've started doing an MSc to go further.

by the way you know about GIS and J2ME coz i'm thinking of doing that 4 z MSc thesis. J2ME is 2 gr8.

but how can u manipulate a map dynamically, i hope u know wat i mean.

We can share our experience and problems to get a solution to any mobile application, wat do u think.

Reply With Quote
  #9  
Old August 31st, 2004, 06:20 PM
jainanchal jainanchal is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 3 jainanchal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 24 sec
Reputation Power: 0
hi
any one know about Voice Recording?

Anchal
Quote:
Originally Posted by vishalneo
hi,
Finally i solved my previous problem on my own.
Now i want to know how to connect to a database and retrieve many records and display on a mobile, using j2me.

bye.

Reply With Quote
  #10  
Old September 14th, 2004, 10:38 PM
boon boon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 boon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 5 sec
Reputation Power: 0
Unhappy facing problem :(

hi everyone...

i have some problems when connecting my midlet to database.

It shows this:

Warning: To avoid potential deadlock, operations that may block, such as
networking, should be performed in a different thread than the
commandAction() handler.

please help me...thank u

Reply With Quote
  #11  
Old October 16th, 2004, 01:41 AM
bhushan7sag bhushan7sag is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 bhushan7sag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question

Hi,
Can I use JDBC in my java program to access local database which is stored on PDA in DBMSs like HSQLDB or SQLIte.
I m new to J2ME and developing java application to be deployed on PDA which wud access database on server as well as tht on PDA.As for the server part it appears(if i m not wrong) from the messages here that I 'll have to use midlets and servelets with JDBC.
But what about local database on the PDA device.Can i use JDBC here too.If yes pls tell how.If no what r other options for this task.
Kindly help!!
Vishal and Frankie,expecting a response from u too.
Thanks in advance.
Kind regards.
Bhushan.

Reply With Quote
  #12  
Old November 2nd, 2004, 02:24 AM
londy84 londy84 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 londy84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Good People

I'm trying to implement the Music on demand Application. I'm trying to complete the Wireless Project for Mobile Music On Demand. The application have to Play Music, Download and save Music Files (Which I think it can work with two databases with the original files stored at one Databases and downloaded to another Databases by Copying from the first one and INSERTING to the second Database).

But my problem is that I'm new to J2ME Environment though I've managed to Develop the prototype (only the GUI's).

MAY YOU PLEASE ASSIST ME IF YOU KNOW HOW TO CONNECT TO DATABASE USING J2ME AND STORING AND RETRIEVING MUSIC FILES.

May you pls reply with the snip of Code in Connecting to Databases Using Servlet. I am using MS Access Database but I can also try to use mysql if it can help.


PLEASE ASSIST INT HIS REGARD,
Thanks in advance for your flowing responses!!!

Reply With Quote
  #13  
Old November 2nd, 2004, 02:48 AM
londy84 londy84 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 3 londy84 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally Posted by FrankieShakes
Hi Vishalneo,

This is another topic of great interest.... Especially those who first get into J2ME... I also thought the same: query the DB right from within the MIDlet.

For simplicity (again, J2ME is meant to be lightweight), you should consider creating a Servlet (assuming you're using Java on the server) that connects to the database, retrieves the records, and then passes it back to the MIDlet. So rather than having the MIDlet connect to your Oracle/MySQL/Whatever database, it calls the Servlet, which then queries the database and returns to the results to the calling client (MIDlet).

Hope this helps...

Is it possible to RETRIEVE data from Databases and post (display) it back to the Servlet Text fields. For Example (For a user to modify his/her profile s/he have to view the previously entered information the s/he can further modify the information and resubmit it to update the existing data records, ). I know only how to do this with simple Java. Please assist.

Thanking you in advance,
Londy,

Reply With Quote
  #14  
Old November 2nd, 2004, 10:02 AM
vishalneo vishalneo is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: mauritius
Posts: 9 vishalneo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 17 sec
Reputation Power: 0
Cool database update

HI,

if u mean for j2me, then the simple trick is as follows:

1. make ur servlet retrieve all the fields from the database.
2. concatenate each fields with a special character, i use %, into a whole string.
ex:name%surname%address%...
3. then send the entire string to the j2me client.
4. on the client side, de-concatenate the string into the original fields.
5. always make it return a fixed/known number of fields so that u can manipulate easily.
6. assign each field to a textfield.
7. edit the fields on the client.
8. then concatenate again all the fields into a string and send to the servlet to update the database.

hope it helps,
neo

Reply With Quote
  #15  
Old August 19th, 2007, 02:35 PM
abeera_ilyas abeera_ilyas is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 1 abeera_ilyas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 9 sec
Reputation Power: 0
Unhappy J2ME connection prob with database

im new to J2ME language n dont knw much abt it but i have chosen it as a tool for my final project so really needed help on urgent....
im making an application that connects to a db made in ACCESS and tells the user location of hospitals in a specific city.

now wht i want to knw is all the basics of J2ME that would b needed to understand the connectivity n the language...since im new to it

2. i want to knw how the application wud connect to the internet to access the database.
3. i need to knw the way to query the database n show the user response according to his selection.

plz i need help, n if some one can tell me abt the packages n class handling in J2ME, tht wud b highly appreciated.

rough coding for the application is also welcomed.....
from
desparate programmer

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > accessing database from midlets n returning many records


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap