为了读取DB值(mySQL),我计划在scala中实现DAO。我正在检查此代码(在Java中)以供参考- https://dzone.com/articles/building-simple-data-access-layer-using-jdbc
我是DAO和scala的新手,我在构造函数中面临着一个可能很简单的问题,但无法修复
这是我为此创建的构造函数:
class Pet ()
{
var name: String
var owner: String
var species: String
var sex: String
var birth: String
//var death: String
def getname()=name
def setname(name:String): Unit ={
this.name=name
}
def getowner()=owner
def setowner(owner: String)={
this.owner=owner
}
def getspecies()=species
def setspecies(species:String)={
this.species=species
}
def getsex()=sex
def setsex(sex:String)={
this.sex=sex
}
def getbirth()=birth
def setbirth(birth:String)={
this.birth=birth
}
/*
def getdeath()=birth
def setdeath()={
this.death=death
}
*/
}
这是我要向Pet对象添加成员变量的方式
val petObj = new Pet()
petObj.setname(rs.getString("name"))
petObj.setowner(rs.getString("owner"))
petObj.setspecies(rs.getString("species"))
petObj.setsex(rs.getString("sex"))
petObj.setbirth(rs.getString("birth"))
在上述构造函数中,我遇到了编译时错误
宠物类必须声明为抽象或实现成员“所有者”