错误是:
java.lang.NoClassDefFoundError: com/mongodb/MongoTimeoutException
bean.Dao.getValue(Dao.java:18)
bean.Login.doPost(Login.java:60)
*
包装豆; 导入java.net.UnknownHostException; 导入org.apache.log4j.Logger; 导入com.mongodb.BasicDBObject; 导入com.mongodb.DB; 导入com.mongodb.DBCollection; 导入com.mongodb.DBCursor; 导入com.mongodb.MongoClient; 导入com.mongodb.MongoTimeoutException;
public class DBConnection1 {
static MongoClient mongoClient ;
private static final Logger logger=Logger.getLogger(DBConnection1.class);
public static DB getCollection(){
// TODO Auto-generated method stub
try{
mongoClient = new MongoClient( "gpd-56b-bc56.nam.nsroot.net", 27017 );
DB db = mongoClient.getDB( "emportal" );
//LOGGER.info("Connect to database successfully");
String username="emPortalAdmin";
char[] password={'e','m','P','o','r','t','a','l','A','d','m','i','n','1','2','3'};
@SuppressWarnings("deprecation")
boolean auth = db.authenticate(username,password);
//LOGGER.info(auth);
return db;
}
catch(MongoTimeoutException|UnknownHostException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return null;
}
}
DAo.java文件
package bean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
public class Dao {
public static String getValue()throws Exception {
DBCursor cursor=null;
String env=null;
DB db=DBConnection1.getCollection();
DBCollection coll=db.getCollection("Employee");
List<String> envlist=new ArrayList<String>();
cursor=coll.find();
while(cursor.hasNext())
{
DBObject obj = cursor.next();
env=(String)obj.get("Employeeid");
if(!env.equalsIgnoreCase("NA")){
envlist.add(env);
}
}
cursor.close();
//// DBConnectionUtil.mongoClient.close();
Collections.sort(envlist);
return env;
}
}
从该文件调用Examlpe.java
package bean;
public class Example {
public static void main(String[] args) throws Exception { // TODO Auto-generated method stub
Dao k = new Dao();
String dfd=Dao.getValue();
System.out.println("sdsd"+dfd);
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。