【发布时间】:2015-08-16 05:05:37
【问题描述】:
我的设计中有 2 个名为 Male 和 Female 的 JRadioButtons。在源代码的末尾,我声明了一个名为gender 的私有字符串变量。然后在我指定的 Jradiobutton 动作执行事件中,
在 jradio button1 中执行的动作事件 性别=“男”
在 jradio button2 中执行的动作事件 性别=“女”
在我的数据库中,我有一个名为 Gender 的列,所以我需要知道的是,当我单击表单中的“添加”按钮时,我需要将选定的 jradiobutton 值(男性或女性)插入数据库。
在我的添加按钮的操作执行事件中我已经这样做了,我不知道如何将 jradioButton 值插入到 db(我需要在 txtname 之后添加它),请告诉我这样做的方法。这是我的代码
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {
try {
int x = JOptionPane.showConfirmDialog(null,
"Do You Want to add this Record?");
if (x == 0) {
Connection c = DBconnect.connect();
Statement s = (Statement) c.createStatement();
s.executeUpdate("INSERT into employee VALUES('"
+ txtEmpId.getText() + "','" + txtName.getText()+"')");
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
-
性别的数据库字段类型是什么?
-
我已将其作为 varchar(10)
-
然后插入
gender字符串值
标签: java jdbc netbeans-8 jradiobutton