我有一个名为Album的表有4列,CodeA是char类型的主键。
然后我的第二个表是Collabo,其中一列名为CodeA,它是一个始终为char类型的外键。
here is a preview 我尝试在我的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;
}
答案 0 :(得分:0)
new Album (resu.getString(2))
需要一个带有单个String
参数的构造函数:
public Album(String codeA) {
this.codeA = codeA;
}