java连接mongodb

bichir 2016-12-03 01:29:19
我官网下载的mongodb3.2
驱动用的mongodb3.2.2共三个jar.
bson-3.2.2.jar
mongodb-driver-3.2.2.jar
mongodb-driver-core-3.2.2.jar
我参照
http://www.runoob.com/mongodb/mongodb-java.html
上的写法来做测试
信息: No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, all=[ServerDescription{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 5000 ms before timing out
Dec 03, 2016 1:22:12 PM com.mongodb.diagnostics.logging.JULLogger log
信息: Exception in monitor thread while connecting to server 127.0.0.1:27017
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='test', source='admin', password=<hidden>, mechanismProperties={}}
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:61)
at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:99)
at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:44)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.security.sasl.SaslException: Unable to find PBKDF2WithHmacSHA1. [Caused by java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA1 SecretKeyFactory not available]
at com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient.hi(ScramSha1Authenticator.java:230)
at com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient.computeClientFinalMessage(ScramSha1Authenticator.java:167)
at com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient.evaluateChallenge(ScramSha1Authenticator.java:100)
at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:50)
... 5 more
Caused by: java.security.NoSuchAlgorithmException: PBKDF2WithHmacSHA1 SecretKeyFactory not available
at javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:121)
at javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:159)
at com.mongodb.connection.ScramSha1Authenticator$ScramSha1SaslClient.hi(ScramSha1Authenticator.java:227)
... 8 more

此时的jre用的oralce上下的jdk1.7.0_79版本。
然后我把jre换成myeclipse自带的 sun jdk1.7
却能正常运行了。
在网上上查看驱动说的是支持jdk1.6~1.8。但是为何我用我自己安装的jdk1.7不行呢。

...全文
487 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
luqixi 2019-08-16
  • 打赏
  • 举报
回复
jce.jar sunjce_provider.jar 加到lib目录下
bichir 2016-12-03
  • 打赏
  • 举报
回复
不晓得这个版本啥子特性,少了哪些,我改成oracle上下的,jdk1.8也得行。应该是1.7.0.79少了某些东西。
know_no 2016-12-03
  • 打赏
  • 举报
回复
你好!我没有接触过mongodb,所以无法给你正确的解决方案。 但是,如果你只是换JDK,那会不会是版本不一样呢?还有,查对一下两个JDK的不一致性,及对应的JRE,也许会有所发现。 希望对你解决问题有所用……

51,396

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧