Hi i have written this code and what I am trying in this code is to to get the return value of method to java swing label
here is my code:
public static int search(java.util.Date date)
{
Connection conn = null;
ResultSet rs = null;
Statement st = null;
int b=0;
try
{
conn=DBMgr.openConnection();
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateStr=formatter.format(date);
System.out.println("date"+dateStr);
String sqlQuery = "select sum(time_spend) as Time_Billed_Per_Day,datetime from time_entry where datetime like '"+dateStr+"%' ";
st = conn.createStatement();
rs = st.executeQuery(sqlQuery);
while(rs.next())
{
b = rs.getInt(1);
System.out.println("BILL of the date u specified is:"+b);
}
}
catch(SQLException ex)
{
System.out.println(ex.toString());
}
finally
{
try
{
if(rs!=null)
rs.close();
if(conn!=null)
DBMgr.closeConnection(conn);
}
catch(Exception ex)
{
}
}
return b;
}
This is swings code:
JLabel lblTimeBilledDayText = new JLabel( "00:45:20" , JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);
I want to get the return value of method in place of "00:45:20"
How to do this?
Try this
JLabel lblTimeBilledDayText = new JLabel(String.valueOf(search(date)) , JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);
If b is the return int value then
JLabel lblTimeBilledDayText = new JLabel(new String(Integer.toString(b)), JLabel.RIGHT);
pnlOuter.add(lblTimeBilledDayText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With