missing return statement

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2007
Posts: 8
Reputation: shishir is an unknown quantity at this point 
Solved Threads: 0
shishir shishir is offline Offline
Newbie Poster

missing return statement

 
0
  #1
Mar 19th, 2007
hello everyone.i have just started programming in EJB.i am tring to make an application for online banking system.During the compilation, i am getting the error of missing return statement in all functions where retrun type is String.i am trying to get the output in a JSP page....here is one of the function of my EJB

public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
try
{
ps = conn.createStatement();
String query="INSERT INTO BANK_TRANSACT VALUES('"+userid+"',sys_date,"+amount+",'D','"+branch+"','"+bank+"')";
int result = ps.executeUpdate(query);
if(result>0)
return "Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
return "Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
}


next is the code of jsp from where i am calling the function in my ejb

mybank mbk=null;
InitialContext initial=new InitialContext();
Object objref=initial.lookup("mydatabase");
mybankHome home_ctr=(mybankHome)PortableRemoteObject.narrow(objref,mybankHome.class);
mybank cur_conv=home_ctr.create();
cur_conv.getCustname(ename);
String deposit_amt=request.getParameter("dep_amt");
int amt=Integer.parseInt(deposit_amt);
String act_num=request.getParameter("acc_no");
String branch_id=request.getParameter("br_no");
String bank_name=request.getParameter("bank");
String cust_id=(String)session.getValue("CUST_ID");
String depstmt=cur_conv.ins_Deposit(cust_id,amt,branch_id,bank_name);


please help
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: missing return statement

 
0
  #2
Mar 19th, 2007
Try this way
public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
String output;
try
{
ps = conn.createStatement();
String query="INSERT INTO BANK_TRANSACT VALUES('"+userid+"',sys_date,"+amount+",'D','"+branch+"','"+bank+"')";
int result = ps.executeUpdate(query);
if(result>0)
output = "Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
output = "Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
return output;
}
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 8
Reputation: shishir is an unknown quantity at this point 
Solved Threads: 0
shishir shishir is offline Offline
Newbie Poster

Re: missing return statement

 
0
  #3
Mar 19th, 2007
thanx alot, it really did solve the problem
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,421
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 258
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: missing return statement

 
0
  #4
Mar 19th, 2007
Originally Posted by peter_budo View Post
Try this way
public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
String output;
try
{
ps = conn.createStatement();
String query="INSERT INTO BANK_TRANSACT VALUES('"+userid+"',sys_date,"+amount+",'D','"+branch+"','"+bank+"')";
int result = ps.executeUpdate(query);
if(result>0)
output = "Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
output = "Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
return output;
}
That will probably return that "output" may not have been initialized (if an Exception occurs before the if statement) so either initialize output to a value, or assign output a value in the catch block.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: missing return statement

 
0
  #5
Mar 19th, 2007
Originally Posted by masijade View Post
That will probably return that "output" may not have been initialized (if an Exception occurs before the if statement) so either initialize output to a value, or assign output a value in the catch block.
yes, that is true :cheesy:
still in process of learning

but then I think I would use finally instead, and in catch I would assign error message to output string
Last edited by peter_budo; Mar 19th, 2007 at 11:26 am.
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC