Это мой DAO. Он состоит из public static method for presentationBean
, public static method for lecturerBean
и, наконец, public static PresentationBean addavailable2(PresentationBean ADbean)
для доступа к базе данных.Значение не может быть передано другому публичному статическому методу (java)
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;
}
Моя проблема, я не могу передать значение lecturerID от public static method for lecturerBean
к public static PresentationBean addavailable2(PresentationBean ADbean)
потому lecturerID
не существует в PresentationBean
. Я знаю об этом.
Итак, как я могу пройти lecturerID
от public static method for lecturerBean
до public static PresentationBean addavailable2(PresentationBean ADbean)
. Я попытался объявить новый LecturerBean
в public static PresentationBean addavailable2(PresentationBean ADbean)
, но я все еще получаю нулевое значение.
Не нужно указывать весь заголовок метода. Имена методов прекрасны. – DarkV1
Объявите его как переменную класса – DarkV1
Похоже, что 'addavailable2' нуждается в идентификаторе лектора, и вы его не даете. Таким образом, очевидное решение состоит в том, чтобы дать ему один, добавив еще один параметр в метод. – ajb