J2ME Database Handling

I am developing a J2ME application and have no idea how to connect it with the database. I tried it doing, as given in some books but was unsuccessful.  I included the following code in the constructor of MIDLET class

String url = "jdbc:odbc:db1";
String userID = "cse1";
String password = "jss";
Statement DataRequest;
ResultSet Results;
Connection Db;
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
Db = DriverManager.getConnection(url,userID,password);
}
catch (ClassNotFoundException error) {
System.err.println("Unable to load the JDBC/ODBC bridge." +
error);
System.exit(1);
}
catch (SQLException error) {
System.err.println("Cannot connect to the database." + error);
System.exit(2);
}
try {
String query = "SELECT * FROM login";
DataRequest = Db.createStatement();
Results = DataRequest.executeQuery (query);
//Place code here to interact with the ResultSet
DataRequest.close();
}
catch ( SQLException error ){
System.err.println("SQL error." + error);
System.exit(3);
}
Db.close();

I included the "javax.sql" package also, but the emulator does not recognise this package and an error message saying that "this package does not exist" .

I would also like to know the use of TOMCAT server while developing a mobile connection or while accessing the database.

plzzz help as soon as possible.

Shane

You seem to be having a bit of an architectural issue more so than a java/jdbc problem.

If you do have a JDBC driver and a DB running on the device, you can connect to it... It's unlikely to be a JDBC-ODBC bridge, however. If you have a remote DB, the JDBC connection is probably an expensive way to connect from your device to the DB. Regardless, you have to have at least the database's driver installed on your device.

As far as tomcat: what are you trying to do? Are you trying to create a web application that you can surf on your cell phone? Then, from tomcat's viewpoint, it's the same as developing any other web application, except, when you write your markup, it may not be HTML, but WML or CHTML, or some other markup generated by your JSPs/Servlets. Your web application will be connecting to the DB.

Cheers,

RZ

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.