• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

retrieved data from database and tick JTextBox in my form automatically

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I have a JCheckbox on a form and i want to store the info from that JCheckbox into a database (ms access) and also retrieve it back to the form i.e if the checkbox was selected when the form was saved, it should be selected when i retrieve the data.
I had go through all the post and i found only 1 member facing the same problem but seems no respond from u all.....
Thank you....
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you have to do is check for the selection or deselection of the checkbox and then update your database at that time.

Now in regards to setting the checkbox state from a DB entry

Something like that anyway. It should get you started in the right direction.
 
Kevin Ng
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Gregg Bolinger,
Can you show me how to apply this few code into my find class...because when i try to apply this code there were errors which is cannot resolves symbols (pointed to DB.FIELD and the DB stand for database name, FIELD stand for field name??)
boolean CHECKED = false;
if (DB.FIELD == 0) CHECKED = false;
if (DB.FIELD == 1) CHECKED = true;
JCheckBox check = new JCheckBox("Available");
check.setSelected(CHECKED);

Below is my find class:
public class FindRecord implements ActionListener {
public void actionPerformed(ActionEvent e) {
try {
if (!pFnametxt.getText().equals("")&&!pLnametxt.getText().equals("")) {
//start the query here!
String find = "SELECT * FROM contactmanager " +
"WHERE p1stname = '" + pFnametxt.getText() + "'&& plastname = '" + pLnametxt.getText() + "'";
ResultSet rs = statement.executeQuery(find);
boolean moreRecord = rs.next();
if (moreRecord)
{
pLnametxt.setText(rs.getString(2));
pNicktxt.setText(rs.getString(3));
pMobiletxt.setText(rs.getString(4));
pReligiontxt.setText(rs.getString(5));
pEmail1txt.setText(rs.getString(6));
pEmail2txt.setText(rs.getString(7));
pWebtxt.setText(rs.getString(8));
gender.setSelectedItem(rs.getString(9));
pOccupationtxt.setText(rs.getString(10));
oCompanytxt.setText(rs.getString(11));
oAddtxt.setText(rs.getString(12));
oCitytxt.setText(rs.getString(13));
oStatetxt.setText(rs.getString(14));
oZiptxt.setText(rs.getString(15));
oCountrytxt.setText(rs.getString(16));
oPhonetxt.setText(rs.getString(17));
oFaxtxt.setText(rs.getString(18));
oPositiontxt.setText(rs.getString(19));
oDepartmenttxt.setText(rs.getString(20));
oEmailtxt.setText(rs.getString(21));
oWebtxt.setText(rs.getString(22));
hAddtxt.setText(rs.getString(23));
hCitytxt.setText(rs.getString(24));
hStatetxt.setText(rs.getString(25));
hZiptxt.setText(rs.getString(26));
hCountrytxt.setText(rs.getString(27));
hPhonetxt.setText(rs.getString(28));
hFaxtxt.setText(rs.getString(29));
textArea.setText(rs.getString(30));
pBirthtxt.setText(rs.getString(31));
phototxt.setText(rs.getString(32));
//reminder.setSelected(rs.getBoolean(33));
}
else
JOptionPane.showMessageDialog(null,"No such Record!");
}
else
JOptionPane.showMessageDialog(null,"Enter First Name And Last Name To Find!");
}
catch (SQLException sqlex) {
sqlex.printStackTrace();
JOptionPane.showMessageDialog(null, "Error: " + sqlex.toString());
}
catch (Exception ee) {
ee.printStackTrace();
JOptionPane.showMessageDialog(null, "Errorlah ! " +
ee.toString());
}
}
}
THANK YOU SO MUCH!
reply
    Bookmark Topic Watch Topic
  • New Topic