【问题标题】:how to insert jcombobox value in Mysql database如何在 Mysql 数据库中插入 jcombobox 值
【发布时间】:2014-06-06 17:07:10
【问题描述】:

如何在 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);
    }
}       

【问题讨论】:

  • 你必须发布你的数据库表结构。这会很有帮助。似乎是您插入了一些不匹配的数据或更少的列,并且您传递给插入查询的数据过多

标签: java swing jdbc jcombobox


【解决方案1】:

试试(String)jComboBox1.getSelectedItem();,你必须转换成字符串。

这是你的代码。

obj.st.execute("insert into std  values('"+jTextField1.getText()+"', '"+jTextField2.getText()+"','"+jTextField3.getText()+"','"+jTextField4.getText()+"',"+(String)jComboBox1.getSelectedItem()+"')");

【讨论】:

  • 出现这些期望?? 2014 年 6 月 6 日上午 10:19:27 College.managment.system.studentsetp jButton3ActionPerformed 严重:空
  • 我不明白,你在说什么?
猜你喜欢
  • 2023-03-22
  • 2012-11-16
  • 1970-01-01
  • 1970-01-01
  • 2023-03-13
  • 2015-06-18
  • 1970-01-01
  • 1970-01-01
  • 2017-06-20
相关资源
最近更新 更多