Try this way ;)
public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
<strong>String output;</strong>
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)
<strong>output = </strong>"Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
<strong>output = </strong>"Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
<strong>return output;</strong>
}
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901
Try this way ;)
public String ins_Deposit(String userid,int amount,String branch,String bank) throws SQLException
{
Statement ps = null;
<strong>String output;</strong>
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)
<strong>output = </strong>"Transaction successfully completed,amount will be credited to your account within 24hrs. ";
else
<strong>output = </strong>"Bank timings are between 8 AM to 8 PM IST,Record not inserted";
}
catch(SQLException e)
{
System.out.println("Unable to get Data: " + e);
}
<strong>return output;</strong>
}
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.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
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
peter_budo
Code tags enforcer
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 901