Connecting to a MongoDB with Android in Eclipse

2019-05-14 04:47发布

I am currently developing an Android application, which is going to use a database from MongoLab. Another member of my team has already created a working database on mongolab.com, I am just having trouble connecting to it via Eclipse.

I have looked all around Google and at countless tutorials, but I really don't know much about what I'm doing.

The best tutorial I have found is from mkyong.com. It seems the second section labeled Java MongoDB Examples is what I am looking for, but I cannot get the library being used in those examples imported into my projects.

Is there a URL I can search for in Help >> Install New Software in Eclipse? I have downloaded the mongo-java-driver, but do not know how to incorporate that into my Eclipse.

To clarify again, I have no need to create a MongoDB, I am just trying to connect to an existing database via an Android project in Eclipse.

3条回答
你好瞎i
2楼-- · 2019-05-14 04:56

You must add the driver jar to your CLASSPATH, please refer to this FAQ.

If you have done this correctly Eclipse should be able to provide import for the the Mongo class if you type something like:

Mongo mongo = new Mongo("localhost", 27017);
查看更多
Juvenile、少年°
3楼-- · 2019-05-14 05:06

Java Mongo driver 2.6 is compatible with Android.

The actual version 3.0.3 isn't compatible with Android because javax.security.sasl.* isn't implemented on Android.

I'm working on a forked version of 3.0.3 adding javax.security.sasl classes of this project https://github.com/koterpillar/android-sasl

查看更多
女痞
4楼-- · 2019-05-14 05:18

I think you need to use the rest API provided by the Mongo Lab , not the java API. Send Http call to the server and get the response and parse it using JSON Parsor, that should do it.

查看更多
登录 后发表回答