Dies ist mein DAO. Es besteht aus public static method for presentationBean
, public static method for lecturerBean
und zuletzt public static PresentationBean addavailable2(PresentationBean ADbean)
für den Zugriff auf die Datenbank.Wert kann nicht in eine andere öffentliche statische Methode (Java) übergeben werden
public class AddAvailableDAO2 {
static Connection currentCon = null;
static ResultSet rs = null;
public static PresentationBean getPresentation(String id) throws SQLException, ClassNotFoundException
{
currentCon = JavaConnectionDB.getConnection() ;
PreparedStatement ps = currentCon.prepareStatement("SELECT * FROM presentation WHERE presentationid = ?") ;
ps.setString(1, id) ;
PresentationBean pb = new PresentationBean() ;
ResultSet rs = ps.executeQuery() ;
while(rs.next())
{
pb.setPresentationID(rs.getString(1)) ;
pb.setPresentationDay(rs.getString(2)) ;
pb.setPresentationStart(rs.getDate(3)) ;
pb.setPresentationEnd(rs.getDate(4)) ;
}
return pb ;
}
public static LecturerBean getLecturer(String lectID) throws SQLException, ClassNotFoundException
{
currentCon = JavaConnectionDB.getConnection() ;
PreparedStatement ps1 = currentCon.prepareStatement("SELECT * FROM lecturer WHERE lecturerid = ?") ;
ps1.setString(1, lectID) ;
LecturerBean lb = new LecturerBean() ;
ResultSet rs1 = ps1.executeQuery() ;
while(rs1.next())
{
lb.setLecturerID(rs1.getString(1)) ;
}
return lb ;
}
public static PresentationBean addavailable2(PresentationBean ADbean) {
System.out.println("JIJIJI");
AvailabilityBean available = new AvailabilityBean();
String availableID = ADbean.getPresentationID();
String availableDay = ADbean.getPresentationDay();
String availID = available.getAvailableID();
LecturerBean lb = new LecturerBean();
String lecturerID = lb.getLecturerID();
try{
currentCon = JavaConnectionDB.getConnection();
SimpleDateFormat date1 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
Date availStart = ADbean.getPresentationStart();
Date availEnd = ADbean.getPresentationEnd();
String avs = date1.format(availStart);
String ave = date1.format(availEnd);
String start = "02-05-2016 " + avs.substring(11);
String end = "02-05-2016 " + ave.substring(11);
Date StartTime = date1.parse(start);
Date EndTime = date1.parse(end);
java.util.Date availableStart = new java.util.Date();
java.sql.Date avStart = new java.sql.Date(StartTime.getTime());
java.util.Date availableEnd = new java.util.Date();
java.sql.Date avEnd = new java.sql.Date(EndTime.getTime());
PreparedStatement ps=currentCon.prepareStatement("Insert into free (freeID,lecturerID,availableID) select free_seq.nextval,?,availableID from availability where availableday=? AND availableStart=?");
ps.setString(1,lecturerID); //PASS THE VALUE TO HERE
ps.setString(2,availableDay);
ps.setDate(3, avStart);
ps.executeUpdate();
}
catch(Exception e){
System.out.println("add availability failed 2: An Exception has occurred! " + e);
e.printStackTrace() ;
System.out.println("Your availability Day is " + availableDay);
}
return ADbean;
}
Mein Problem ist, ich nicht den Wert von lecturerID von public static method for lecturerBean
zu public static PresentationBean addavailable2(PresentationBean ADbean)
weil lecturerID
in PresentationBean
existiert nicht passieren kann. Ich bin mir dessen bewusst. Wie kann ich die lecturerID
von public static method for lecturerBean
zu public static PresentationBean addavailable2(PresentationBean ADbean)
übergeben. Ich habe versucht, LecturerBean
in public static PresentationBean addavailable2(PresentationBean ADbean)
neu zu deklarieren, aber ich bekomme immer noch null Wert.
Es ist nicht notwendig, den gesamten Methodenkopf anzugeben. Methodennamen sind in Ordnung. – DarkV1
Deklarieren Sie es als eine Klassenvariable – DarkV1
Es sieht aus wie 'Addavailable2' benötigt eine Dozenten ID, und Sie geben es nicht eine. Die naheliegende Lösung besteht also darin, einen zu geben, indem der Methode ein weiterer Parameter hinzugefügt wird. – ajb