title: Setting jtextfield to a database result
body: <p>I've been trying to work this problem out for a while now and it seems to be eluding me. Now I could be missing something ever so simple and I'm sorry in advance if it is.</p>
  
  <p>I'm trying to display the result from an SQL sum into a JTextField. Now I can make the result appear in a JTable but I can't seem to get it into a JTextField.</p>
  
  <p>The code is below:</p>
  
  <pre><code>String start = ((JTextField)startDate.getDateEditor().getUiComponent()).getText();
  String end = ((JTextField)endDate.getDateEditor().getUiComponent()).getText();
  String sql = "SELECT SUM(OD_GROSS) FROM ORD_DETAIL WHERE OD_ACCOUNT = ? AND OD_DATE BETWEEN '"+start+"' AND '"+end+"'";
  
  pst = conn.prepareStatement(sql);
  pst.setString(1, txtAccountNumber.getText());
  
  rs = pst.executeQuery();
  tblTotal.setModel(DbUtils.resultSetToTableModel(rs));
  
  } catch (Exception e) {
  JOptionPane.showMessageDialog(null, e);
  }
  </code></pre>
  
  <p>The above code does work and shows the sum in a JTable. But if anybody knows how I might get the result into a JTextField that would be great.</p>
  
  <p>Thank you in advance.</p>