Hello AbrahamH,
The BB doesn't really connect directly to a database. It will require either a web service or a web page on the server that the BB will access for its database access.
If you can use a web service, then the MDS Studio should be fairly easy to get something working.
If you need a web page, then your BB app will have to send/receive data via an http connection. Search around for http connection and there is lots of good examples out there.
I have used a web page to retrieve data from the database that then "writes" the data in XML format.
Here's some sample code to get you started.
Code:
public static void readdb(String _param) {
String XMLvalues = "";
// Pass parameter to url
String url = "http://yourserver.com/yourpage.aspx?param="+_param+";deviceside=false";
// Load data from server
XMLvalues = getHttp(url);
// Process data returned....
}
public static String getHttp(String url) {
String XMLvalues = "";
HttpConnection h = null;
InputStream dis = null;
OutputStream dos = null;
int response;
boolean keepGoing = true;
boolean _error = false;
int retry = 3;
try {
h = (HttpConnection)Connector.open(url);
// Set the request method and headers
h.setRequestMethod(HttpConnection.POST);
h.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
h.setRequestProperty("Content-Language", "en-US");
dis = h.openInputStream();
while (keepGoing) {
int status = h.getResponseCode();
switch (status) {
case (HttpConnection.HTTP_OK):
// Connection is 200 OK.
// Ready to send data.
keepGoing = false;
break;
case (HttpConnection.HTTP_BAD_REQUEST):
// Bad Request, try again
retry--;
if (retry > 0) {
h.close();
// Open a new connection.
h = (HttpConnection)Connector.open(url);
// Set the request method and headers
h.setRequestMethod(HttpConnection.POST);
h.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
h.setRequestProperty("Content-Language", "en-US");
dis = h.openInputStream();
} else {
_error = true;
keepGoing = false;
}
break;
case (HttpConnection.HTTP_NOT_FOUND):
// File not found
_error = true;
keepGoing = false;
break;
default:
// The connection failed for some other reason.
_error = true;
keepGoing = false;
break;
}
}
// Read input if no errors
if (!_error) {
final StringBuffer sb = new StringBuffer();
int ch;
String type = h.getType();
while ((ch = dis.read()) != -1) {
if (ch > 0x7F) ch = 0x20;
sb.append((char) ch);
}
XMLvalues = sb.toString();
}
} catch (IOException ioe) {
System.out.println(ioe.toString());
} finally {
if (dos != null) {
try {
dos.close();
} catch (Exception e) {
}
}
if (dis != null) {
try {
dis.close();
} catch (Exception e) {
}
}
if (h != null) {
try {
h.close();
} catch (Exception e) {
}
}
}
// Return results
return XMLvalues;
}
fbrimm