944,131 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2424
  • Java RSS
Mar 19th, 2007
0

missing return statement

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shishir is offline Offline
8 posts
since Mar 2007
Mar 19th, 2007
0

Re: missing return statement

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;
}
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Mar 19th, 2007
0

Re: missing return statement

thanx alot, it really did solve the problem
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shishir is offline Offline
8 posts
since Mar 2007
Mar 19th, 2007
0

Re: missing return statement

Click to Expand / Collapse  Quote originally posted by peter_budo ...
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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Mar 19th, 2007
0

Re: missing return statement

Click to Expand / Collapse  Quote originally posted by masijade ...
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.
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: NAtive compailers
Next Thread in Java Forum Timeline: How to store array?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC