Hey Guys im newby to Java! Help Needed! Please Help Needed!
This is How it Goes!
DAO.java
private BookRecordViews populateBookObject (ResultSet Results)
throws ClassNotFoundException , SQLException
{
int BookID = Integer.parseInt(Results.getString("BookID"));
String BookName = Results.getString("BookName");
String DateOfArrival = Results.getString("DateOfArrival");
String DateOfPublish = Results.getString("DateOfPublish");
String AuthorName = Results.getString("AuthorName");
int StudentID = Integer.parseInt(Results.getString("StudentID"));
int LecturerID = Integer.parseInt(Results.getString("LecturerID"));
String Available = Results.getString("Available");
String Category = Results.getString("Category");
return new BookViews(BookID, BookName, DateOfArrival, DateOfPublish, AuthorName, StudentID, LecturerID, Available, Category);
} // This Method Populates the Book Records and gets the fields from BookViews.java
public ArrayList<BookRecordViews> GetBookRecord()
throws ClassNotFoundException , SQLException
{
try
{
ArrayList<BookRecordViews> BookRecords = new ArrayList<BookRecordViews>();
Statement SQLStatement = getDatabaseConnection();
String SQLQuery = "SELECT * FROM Book;";
ResultSet BookResult = SQLStatement.executeQuery(SQLQuery);
while(BookResult.next())
{
BookRecords.add(populateBookObject(BookResult));
}
DestroySQLConnection();
return BookRecords;
}
catch (ClassNotFoundException cnfe)
{
System.out.println(cnfe);
throw cnfe;
}
catch (SQLException SQLE)
{
System.out.println(SQLE);
throw SQLE;
}
} //This Is The Arraylist from where Records Concerning the Books are listed in Array.
BookRecordViews.java
package DataAccessObject;
/**
*
* @author Sagar Joshi
*/
public interface BookRecordViews {
public int getBookID();
public void setBookID(int BookID);
public String getBookName();
public void setBookName(String BookName);
public String getDateOfArrival();
public void setDateOfArrival(String DateOfArrival);
public String getDateOfPublish();
public void setDateOfPublish(String DateOfPublish);
public String getAuthorName();
public void setAuthorName(String AuthorName);
public int getStudentID();
public void setStudentID(int StudentID);
public int getLecturerID();
public void setLecturerID(int LecturerID);
public String getAvailability();
public void setAvailability(String Available);
public String getCategory();
public void setCategory(String Category);
} // Variables Are Listed.
BookViews.java
package DataAccessObject;
/**
*
* @author Sagar Joshi
*/
public class BookViews implements BookRecordViews {
private int BookID;
private String BookName;
private String DateOfArrival;
private String DateOfPublish;
private String AuthorName;
private int StudentID;
private int LecturerID;
private String Available;
private String Category;
public BookViews()
{
}
public BookViews(int BookID , String BookName , String DateOfArrival , String DateOfPublish , String AuthorName , int StudentID , int LecturerID
, String Available , String Category)
{
this.BookID = BookID;
this.BookName = BookName;
this.DateOfArrival = DateOfArrival;
this.DateOfPublish = DateOfPublish;
this.AuthorName = AuthorName;
this.StudentID = StudentID;
this.LecturerID = LecturerID;
this.Available = Available;
this.Category = Category;
}
public int getBookID()
{
return BookID;
}
public void setBookID(int BookID)
{
this.BookID = BookID;
}
public String getBookName()
{
return BookName;
}
public void setBookName(String BookName)
{
this.BookName = BookName;
}
public String getDateOfArrival()
{
return DateOfArrival;
}
public void setDateOfArrival(String DateOfArrival)
{
this.DateOfArrival = DateOfArrival;
}
public String getDateOfPublish()
{
return DateOfPublish;
}
public void setDateOfPublish(String DateOfPublish)
{
this.DateOfPublish = DateOfPublish;
}
public String getAuthorName()
{
return AuthorName;
}
public void setAuthorName(String AuthorName)
{
this.AuthorName = AuthorName;
}
public int getStudentID()
{
return StudentID;
}
public void setStudentID(int StudentID)
{
this.StudentID = StudentID;
}
public int getLecturerID()
{
return LecturerID;
}
public void setLecturerID(int LecturerID)
{
this.LecturerID = LecturerID;
}
public String getAvailability()
{
return Available;
}
public void setAvailability(String Available)
{
this.Available = Available;
}
public String getCategory()
{
return Category;
}
public void setCategory(String Category)
{
this.Category = Category;
}
} // Contains The Getter and Setter Method.
ViewBooks.jsp
<%
// The Importance of Having JSPs is to be Present Contents on the Web Pages. They Are Known very Famous for
// displaying Web Contents. Having Database Connections and performing SQL Manipulations on the JSPs can make
// JSPs congested with Codes that are to be actually used in Servlets. A Further Explanation on this Point
// takes us deeper in to the DAO (Data Access Object) Design Pattern. As You Can See the ViewBooks.jsp
// has the DAO File Imported and the Method GetBookRecord() has been called in the JSP rather than
// establishing the SQL Connection, performing the SQL Statement and then projecting the Data.
OshwalDAO dao = DAO.getDAOInterface();
ArrayList GetBookRecord = dao.GetBookRecord();
//String StudentRecord = dao.GetStudentRecordForDelete();
%>
<table align="center" border="1" frame="2" id="table" width="1020">
<tr><td><b>Book ID</b></td><td><b>Book Name</b></td><td><b>Date Of Arrival</b></td><td><b>Date Of Publish</b></td><td><b>Author Name</b></td><td><b>Student ID</b></td>
<td><b>Lecturer ID</b></td><td><b>Available</b></td><td><b>Category</b></td></tr>
<% BookRecordViews Book;
for(Iterator i = GetBookRecord.iterator(); i.hasNext();) {
Book = (BookRecordViews)i.next();
%>
<tr>
<td><%=Book.getBookID()%></td>
<td><%=Book.getBookName() %></td>
<td><%=Book.getDateOfArrival() %></td>
<td><%=Book.getDateOfPublish() %></td>
<td><%=Book.getAuthorName() %></td>
<td><%=Book.getStudentID() %></td>
<td><%=Book.getLecturerID() %></td>
<td><%=Book.getAvailability()%></td>
<td><%=Book.getCategory()%></td>
<td><a href="UpdateBook.jsp?BookName=<%=Book.getBookName()%>">Update</a></td>
</tr>
<% } %>
</table>
</body>
</html>
//In The JSP it is just getting all the records. Now How should i modify such that it displays one record only and then i click on next and it displays the next record. I know i have used an Array but dnt knw what to implement. PLEASE HELPPPPPPPPPPPPPPPP!