why doesnt updateProp() works?

here is the code....it compiles fine..but there is a problem with the query executed in updateProp(). the log doesnt contain any information about it....please help..

// 2nd version, with reminders being set on database

import java.sql.*;

import javax.servlet.*;

import javax.servlet.http.*;

import javax.naming.*;

import javax.sql.*;

import java.io.*;

import java.util.*;

//import beans.User;

public class NewTenServlet extends HttpServlet {

private String target="/welcomeL.jsp";

private String url="jdbc:mysql://localhost:3306/agent";

Connection con=null;

PreparedStatement ps,ps2,ps3,ps4;

ResultSet rs=null;

//HttpSession session;

String tname,temail,tpass, tpass2;

Integer id;

int pid,tid;

String mode;

public void init(ServletConfig config)

throws ServletException {

super.init(config);

}

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

// If it is a get request forward to doPost()

doPost(request, response);

}

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

System.out.println("=========================================================");

System.out.println("Add new tenant");

HttpSession session=request.getSession();

ServletContext context = getServletContext();

try{

id=(Integer)session.getAttribute("pid");

pid=id.intValue();

}

catch(Exception e){

e.printStackTrace();

System.out.println("Dta not retrieved from session");}

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

con=DriverManager.getConnection(url,"root", "ketson");

System.out.println("Connection established");

}

catch(Exception e){

System.out.println("unsuccessful connection");

e.printStackTrace();

}

try{

tname = request.getParameter("name");

temail=request.getParameter("email");

tpass=request.getParameter("pass");

ps =con.prepareStatement("INSERT INTO users(user_name, pass, email, status)"+

"values(?,?,?,2)");

ps.setString(1, tname);

ps.setString(2, tpass);

ps.setString(3, temail);

ps.executeUpdate();

System.out.println("user query executed");

}

catch(Exception e){

System.out.println("Query not executed");

e.printStackTrace();

}

//get new tenant id

try{

ps2 =con.prepareStatement("Select uid FROM users WHERE user_name=?");

ps2.setString(1, tname);

rs= ps2.executeQuery();

while(rs.next()){

tid=rs.getInt("uid");

}

System.out.println("2nd user query executed");

}

catch(Exception e){

System.out.println("2nd Query not executed");

e.printStackTrace();

}

//get property mode...

try{

ps3 =con.prepareStatement("Select mode FROM property WHERE pid=?");

ps3.setInt(1, pid);

rs= ps3.executeQuery();

while(rs.next()){

mode=rs.getString("mode");

}

System.out.println("mode= "+mode+tid+pid);

}

catch(Exception e){

System.out.println("mode Query not executed");

e.printStackTrace();

//use tenant id to modify property details

updateProp(pid,tid,mode); //this is where the problem lies

System.out.println("successful property update");

try{

System.out.println("redirecting to succesfull update");

RequestDispatcher dispatcher =

context.getRequestDispatcher(target);//redirect to landlord page

dispatcher.forward(request, response);

}

catch(Exception ex){

System.out.println("not redirected");

e.printStackTrace();

}

}

}

public void destroy() {

try{

con.close();

}

catch(SQLException e){

System.out.println(

"Error closing the db connection: "

+ e.getMessage());

}

}

publicvoid updateProp(int p, int t, String m){

try{

System.out.println(" Starting evaluation");

if(m.equals("w")){

System.out.println(" mode is weekly");

ps4 =con.prepareStatement("UPDATE property SET tid=?,start=curdate(),days_due=adddate(start, 7) WHERE pid=?");

ps4.setInt(1, t);

ps4.setInt(2, p);

ps4.executeUpdate();

}

else if(m.equals("m")){

System.out.println(" mode is monthly");

ps4 =con.prepareStatement("UPDATE property SET tid=?,start=curdate(),days_due=adddate(start, 31) WHERE pid=?");

ps4.setInt(1, t);

ps4.setInt(2, p);

ps4.executeUpdate();

System.out.println(" property update query executed");

}

}

catch(SQLException e2){

System.out.println("property update Query not executed");

e2.printStackTrace();

}

} //ENDS UPDATEpROP

}

//}

[5077 byte] By [ketsona] at [2007-10-3 2:30:15]
# 1

In your codes:

try{

ps3 =con.prepareStatement("Select mode FROM property WHERE pid=?");

ps3.setInt(1, pid);

rs= ps3.executeQuery();

while(rs.next()){

mode=rs.getString("mode");

}

System.out.println("mode= "+mode+tid+pid);

}

catch(Exception e){

System.out.println("mode Query not executed");

e.printStackTrace();

//use tenant id to modify property details

updateProp(pid,tid,mode); //this is where the problem lies

You call updateProp(pid,tid,mode) method when your try block failed. This time, maybe your mode is null value. So, in the method updateProp(), if it is not "w" nor "m", it will do nothing there. So, you cann't see any information in log file.

rcd27a at 2007-7-14 19:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thanks for u rreply....

this bit of code >>>>> System.out.println("mode= "+mode+tid+pid); is there to tell me the vaue of the three variables.. before starting updateProp, it prints out in the log all the values of those variables...and they are not null. thats how i know that that is not the reason it doesnt go further....please help

ketsona at 2007-7-14 19:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
its ok..it works now.. the problem was with a cactch clause brace that i closed very late...
ketsona at 2007-7-14 19:29:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...