每日学习
今天完成nosql实验:
mongdb
package opreation; import java.util.ArrayList; import java.util.List; import com.mongodb.DB; import org.bson.Document; import com.mongodb.MongoClient; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; public class MongoTest { public static void main(String[] args) { ; MongoClient mongoClient = new MongoClient("192.168.10.102", 27017); MongoDatabase mongoDatabase = mongoClient.getDatabase("test"); MongoCollection<Document> collection = mongoDatabase.getCollection("student"); Document document = new Document("name", "scofield").append("score",new Document("English", 45).append("Math", 89).append("Computer", 100)); List<Document> documents = new ArrayList<Document>(); documents.add(document); collection.insertMany(documents); System.out.println("文档插入成功"); } }
redis
package opreation; import redis.clients.jedis.Jedis; import java.util.Map; public class jedis_test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Jedis jedis = new Jedis("192.168.10.102"); //输入scofield的成绩信息 jedis.hset("student.scofield", "English", "45"); jedis.hset("student.scofield", "Math", "89"); jedis.hset("student.scofield", "Computer", "100"); Map<String, String> value = jedis.hgetAll("student.scofield"); for (Map.Entry<String, String> entry : value.entrySet()) { //输出scofield的成绩信息 System.out.println(entry.getKey() + ":" + entry.getValue()); } } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步