Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

J2ME Database Handling

  Asked By: Clifford    Date: Apr 25    Category: Java    Views: 975
  

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

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Haboos Kauser     Answered On: Apr 25

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.

 
Didn't find what you were looking for? Find more on J2ME Database Handling Or get search suggestion and latest updates.




Tagged: