File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes bookstore application error.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "bookstore application error.." Watch "bookstore application error.." New topic

bookstore application error..

mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
Hello firends,
I have some problem running this code..-->


portion of register page
<form name="register" action="loginServlet" method="POST">
<h3>Enter Your Details</h3>
<td>First Name : </td>
<td><input type="text" name="firstName"></td>
<input type="submit" value="Register" name="register">
public void doPost (HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
// then write the data of the response
//out.println("<body bgcolor=\"#ffffff\">" + "<center>" + "<hr> <br>  " + "<h1>" + "<font size=\"+3\" color=\"black\">Jayana's Bookstore</font>" + "</h1>" +
//"</center>" + "<br>   <hr> <br> ");
String firstName=request.getParameter("firstName");
String lastName=request.getParameter("lastName");
try {
BookDB bookDb=new BookDB();
int i=0;
System.out.println("There are total "+ i + " Books available");
} catch (Exception e) {
// TODO Auto-generated catch block

and lastly, which accesses he database

public BookDB() throws Exception{


private static Connection getConnection(String strURL,String strUsername, String strPassword){
try {
return DriverManager.getConnection(strURL, strUsername, strPassword);
}catch (SQLException e) {
// TODO Auto-generated catch block
return null;

public void removeConn () {
try {
} catch (SQLException ex) {

public int getNumberOfBooks() {
//public static void main(String args[]){
int count=0;
books=new ArrayList();
String strSQL = "Select * from bookstore.books ";
try {
Connection connMySQL = getConnection("jdbc dbc:mySQLConn", "root", "mallika");
try {
ResultSet rs = connMySQL.createStatement().executeQuery(strSQL);
System.out.println("Book Title : "+rs.getString(4));
} catch (SQLException e) {
// TODO Auto-generated catch block
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block

}catch(Exception e2){
return count;

My problem is- the actions of register page does take me to loginServlet, as i see thishttp://localhost:8080/bookstore1/loginServlet in my browser but it comes to be a blank page..

the BookDB does run and returns 4 books if i run it putting a main() method in it.Why is not my servlet working to access the BookDB and show the result??

Anupama Ponnapalli
Ranch Hand

Joined: Jun 12, 2006
Posts: 66
Did you try uncommenting this line:

//out.println("<body bgcolor=\"#ffffff\">" + "<center>" + "<hr> <br> " + "<h1>" + "<font size=\"+3\" color=\"black\">Jayana's Bookstore</font>" + "</h1>" +
// "</center>" + "<br> <hr> <br> ");
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

I'm surprised the compiler didn't mind that you have a Java class ( that doesn't start with a capital letter.
[ March 12, 2007: Message edited by: Marc Peabody ]

A good workman is known by his tools.
mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
Thanks friends for the reply to my question..

Mark, there shouldnt be any problem if you define a class name with starting letter as small..
its just a good practice to write LoginServlet insted of loginServlet..but not a problem to a compiler..

also wanted to tell that i discoved teh problem,It was because , i had got an object out of Printwriter and i was using System.out.println("") instead of just out.println("");
and this small thing was creating a whole problem , nothing was getting printed to the screen because of this..
But when i took out the System and used out.println everything was fine..

mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
Hello Friends,
here is a question from JPilot exam,

Which of the following are valid uses of the <jsp:useBean> action?
<jsp:useBean id="myBean" class="MyBean" scope="session">
<jsp:useBean id="myBean" class="MyBean"/>
<jsp:useBean id="myBean" class="MyBean" beanName="SomeOtherBean"/>
<jsp:useBean id="myBean" type="MyBean">

My answers were A and B, but it says B and D..
why so?
what is wrong with A??if you say A is not ending with a forward slash"/" but its the same with D. and why is D selected as correct ans?

I agree. Here's the link:
subject: bookstore application error..
It's not a secret anymore!