File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes retrieved data from database and tick JTextBox in my form automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "retrieved data from database and tick JTextBox in my form automatically" Watch "retrieved data from database and tick JTextBox in my form automatically" New topic
Author

retrieved data from database and tick JTextBox in my form automatically

Kevin Ng
Greenhorn

Joined: Aug 31, 2003
Posts: 23
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....
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Kevin Ng
Greenhorn

Joined: Aug 31, 2003
Posts: 23
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!
 
Consider Paul's rocket mass heater.
 
subject: retrieved data from database and tick JTextBox in my form automatically