如何在Mysql数据库中插入jcombobox值?如果不使用 jcombobox 代码可以正常工作吗?
try {
connect obj = new connect();
obj.st = obj.con.createStatement();
boolean a = obj.st.execute("insert into std values('"+jTextField1.getText()+"', '"+jTextField2.getText()+"','"+jTextField3.getText()+"','"+jTextField4.getText()+"','"+(String)jComboBox1.getSelectedItem()+"')");
if(a==false){
System.out.println("Enter successfully");
}
else{
System.out.println("Enter ");
}
} catch (SQLException ex) {
Logger.getLogger(studentsetp.class.getName()).log(Level.SEVERE, null, ex);
}
}
最佳答案
只需尝试使用 (String)jComboBox.getSelectedItem();
,您必须转换为 String。
这是您的代码。
obj.st.execute("insert into std values('"+jTextField1.getText()+"', '"+jTextField2.getText()+"','"+jTextField3.getText()+"','"+jTextField4.getText()+"',"+(String)jComboBox1.getSelectedItem()+"')");
关于java - 如何在Mysql数据库中插入jcombobox值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24087223/