如何在scala中访问mongodb数据库?
我想知道如何从 scala swing 应用程序访问 mongodb 数据库。 我是 scala 新手。我在 mongodb 中创建了一个名为 mydb 的数据库和一个名为 Studen(rollno,name,age,city) 的集合。我只想使用 swing 在 mongodb 数据库上执行插入、更新和删除,但我不知道要使用哪个包以及任何其他有用的信息。
我在这里附上摆动代码。
吉斯卡拉
import swing._
import swing.event._
import swing.Component._
object Gui extends SimpleSwingApplication
{
def top = new MainFrame {
title = "Second Swing App"
val combobox = new ComboBox(List(("1"),("2"),("3"),("4"),("5"),("6"))){
}
val text1= new TextField(10){
}
val text2= new TextField(10){
}
val text3= new TextField(10){
}
val button = new Button {
text = "Clear"
}
val button1 = new Button {
text = "Save"
}
val button2 = new Button {
text = "Delete"
}
val button3 = new Button {
text = "Update"
}
val label = new Label {
text = "No button clicks registered"
}
contents = new BoxPanel(Orientation.Vertical) {
contents += combobox
contents += text1
contents += text2
contents += text3
contents += button
contents += label
contents += button1
contents += button2
contents += button3
border = Swing.EmptyBorder(30, 30, 10, 30)
}
listenTo(button)
reactions+={
case ButtonClicked(button)=>
}
}
I would like to know how to access mongodb database from a scala swing application.
I am new to scala.I have created a database named mydb in mongodb and a collection named studen(rollno,name,age,city). I simply want to perform insert, update and delete with swing on a mongodb database, but i have no idea which package to use and any other information that can be useful.
I am attching the swing code here.
Gui.scala
import swing._
import swing.event._
import swing.Component._
object Gui extends SimpleSwingApplication
{
def top = new MainFrame {
title = "Second Swing App"
val combobox = new ComboBox(List(("1"),("2"),("3"),("4"),("5"),("6"))){
}
val text1= new TextField(10){
}
val text2= new TextField(10){
}
val text3= new TextField(10){
}
val button = new Button {
text = "Clear"
}
val button1 = new Button {
text = "Save"
}
val button2 = new Button {
text = "Delete"
}
val button3 = new Button {
text = "Update"
}
val label = new Label {
text = "No button clicks registered"
}
contents = new BoxPanel(Orientation.Vertical) {
contents += combobox
contents += text1
contents += text2
contents += text3
contents += button
contents += label
contents += button1
contents += button2
contents += button3
border = Swing.EmptyBorder(30, 30, 10, 30)
}
listenTo(button)
reactions+={
case ButtonClicked(button)=>
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 Scala 中使用 MongoDB Java 驱动,也可以使用 Casbah,Java 驱动程序的 Scala 包装器。
You can use the MongoDB Java driver in Scala, or you can use Casbah, a Scala wrapper around the Java driver.