java - 我的构造函数定义不明确?
问题描述
我有一个名为 Album 的表,它有 4 列,CodeA 是 char 类型的主键。
然后我的第二个表是 Collabo,其中包含 1 个名为 CodeA 的列,它始终是 char 类型的外键。
这是 我尝试在我的 Jframe Collabo 中显示 CodeA 的预览,但我的表 DaoCollabo 中有错误消息。
没有找到适合 Album(String) 的构造函数构造函数 Album.Album() 不适用(实际参数列表和正式参数列表长度不同)构造函数 Album.Album(String,String,Chanteur,Date) 不适用(实际参数列表和正式参数列表长度不同)
你觉得我的班级专辑和合作怎么样?
班级相册
public class Album {
private String codeA;
private String titreA;
private Chanteur chantAlb;
private Date dateApp; //
public Album() {
}
public Album(String codeA, String titreA, Chanteur chantAlb, Date dateApp) {
this.codeA = codeA;
this.titreA = titreA;
this.chantAlb = chantAlb;
this.dateApp = dateApp;
}
public String getCodeA() {
return codeA;
}
public void setCodeA(String codeA) {
this.codeA = codeA;
}
public String getTitreA() {
return titreA;
}
public void setTitreA(String titreA) {
this.titreA = titreA;
}
public Chanteur getChantAlb() {
return chantAlb;
}
public void setChantAlb(Chanteur chantAlb) {
this.chantAlb = chantAlb;
}
public Date getDateApp() {
return dateApp;
}
public void setDateApp(Date dateApp) {
this.dateApp = dateApp;
}
public String getDateAppBE() {
String tmp;
if (this.dateApp == null)
tmp = "";
else
{
SimpleDateFormat dateParser = new SimpleDateFormat("dd/MM/yyyy");
tmp = dateParser.format(this.dateApp);
}
return tmp;
}
public void setDateAppBE(String dateApp) {
SimpleDateFormat dateParser = new SimpleDateFormat("dd/MM/yyyy");
try {
this.dateApp = dateParser.parse(dateApp);
} catch (ParseException ex) {
Logger.getLogger(Album.class.getName()).log(Level.SEVERE, null, ex);
}
}
public String getDateAppSQL() {
String tmp;
if (this.dateApp == null)
tmp = "";
else
{
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
tmp = "'" + dateParser.format(this.dateApp) + "'";
}
return tmp;
}
public String getDateAppUS() {
String tmp;
if (this.dateApp == null)
tmp = "";
else
{
tmp = this.dateApp.toString();
}
return tmp;
}
我的课堂协作
public class Collabo {
private Album appAlb;
public Collabo() {
}
public Collabo(Album appAlb) {
this.appAlb = appAlb;
}
public Album getAppAlb() {
return appAlb;
}
public void setAppAlb(Album appAlb) {
this.appAlb = appAlb;
}
DAOCollabo
public ArrayList <Collabo> selectCollabos()
{
ArrayList <Collabo> myList = new ArrayList();
String req = "Select A.CodeA from album A, collabo C where A.CodeA = C.CodeA order by 1 ";
ResultSet resu = ConnexionMySQL.getInstance().selectQuery (req);
try {
while (resu.next())
{
//creation de l'objet Collabo
myList.add (new Collabo(resu.getString(1),
new Album (resu.getString(2))));
}
}
catch (SQLException e)
{
System.out.println(e.toString());
System.exit(-1);
}
return myList;
}
解决方案
new Album (resu.getString(2))
需要一个带有单个String
参数的构造函数:
public Album(String codeA) {
this.codeA = codeA;
}
推荐阅读
- vue.js - 我应该如何更新 vue、computed 和 watcher 中的数据属性似乎并没有这样做
- go - 打印指针引用的地图值
- javascript - 带有谷歌地图和 Ionic 3 的空白页
- ansible - 在 Ansible 中导入时有没有办法引用组变量?
- oracle - Oracle (+) 连接在这种情况下如何工作
- amazon-web-services - Amazon Certificate Manager - 验证问题
- python - 如何从审计字段在 Pandas 中创建摘要行
- r - 在 Azure ML Studio 上为 Microsoft R Open 3.4.4 安装 textshape 包
- bash - 统计特定时间范围内修改的文件数
- node.js - 如何修复strapi内容类型中的“错误:枚举值”?