【问题标题】:Save data from combo box in database Javafx将组合框中的数据保存在数据库 Javafx 中
【发布时间】:2017-05-12 16:59:29
【问题描述】:

我从这个代码行得到一个错误:

prov = obtenerProveedor(productos_comboPROVEEDOR.getSelectionModel().getSelectedItem());

obtenerProveedor() 方法是这样的:

public long obtenerProveedor(String s){
    ConexionMySQL conexion = new ConexionMySQL();
    Connection conn = conexion.conectar();
    String query ="select id from proveedores where nombre = '"+s+"'";
    Statement Squery;
    try{
        Squery = conn.createStatement();
        ResultSet res = Squery.executeQuery(query);
        res.next();
        return res.getLong("id");
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, "No se pudo obtener el proveedor");
    }
    return 0;
} 

我收到以下错误: This one is the error but I can't put images yet

我不确定,但我认为问题在于 obtenerProveedor() 方法要求一个字符串,我向它发送一个对象,但我不知道如何解决它

【问题讨论】:

  • 注释掉字符串查询并在下面添加一个。新的应该是一个完整的硬编码字符串“select .... = ...”。如果可行,请从原始字符串查询中删除 ' 符号。我建议你学习如何使用准备好的语句。
  • 不,是同一个问题

标签: javafx combobox


【解决方案1】:

试试这个

prov = Long.toString(obtenerProveedor(productos_comboPROVEEDOR.getSelectionModel().getSelectedItem()));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多