Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java derby数据库不工作_Java_Mysql_Sql_Jdbc - Fatal编程技术网

Java derby数据库不工作

Java derby数据库不工作,java,mysql,sql,jdbc,Java,Mysql,Sql,Jdbc,这些代码行有什么问题吗?我得到的只是无效条目。 我有一个名为production的数据库和一个名为production的表 try { String mk = jTextField1.getText(); String mn = jTextField2.getText(); String ab = (String) jComboBox1.getSelectedItem(); String bc = (String) jComboBox2.getSelectedIt

这些代码行有什么问题吗?我得到的只是无效条目。 我有一个名为production的数据库和一个名为production的表

try {
    String mk = jTextField1.getText();
    String mn = jTextField2.getText();
    String ab = (String) jComboBox1.getSelectedItem();
    String bc = (String) jComboBox2.getSelectedItem();

    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:1527/production");
        {
            String host = "jdbc:mysql://localhost:1527/production";
            JOptionPane.showMessageDialog(this, "connection success");
            Statement stmt = con.createStatement();

            String query = "update PRODUCT set FACTORY='" + ab + "' PRODUCT_NAME = '" + mk + "' UNIT= '" + bc + "' and OPENING_BALANCE'" + mn + "');";
            stmt.executeUpdate(query);
            JOptionPane.showMessageDialog(this, "Record has been inserted");
            stmt.close();
        }
    } catch (Exception e) {
        JOptionPane.showMessageDialog(this, "invalid entry");
    }
} catch (Exception e) {
    JOptionPane.showMessageDialog(null, "Error in Connectivity", "Message", 2);
}

您的查询不正确:

必须在字段之间使用 设置字段和期初余额“+mn+”时,不需要使用和 在查询的末尾有一个不需要的闭括号 但您的方式可能会出现sytax错误和SQL错误。您必须改用PreparedStatement,它更安全、更有用:

query = "update PRODUCT set FACTORY = ?, PRODUCT_NAME = ?, UNIT= ?, OPENING_BALANCE = ?";
try (PreparedStatement update = connection.prepareStatement(query)) {

    update.setString(1, ab);
    update.setString(2, mk);
    update.setString(3, bc);
    update.setString(4, mn);

    update.executeUpdate();
}

OT:你的第一次尝试。。。。这是干什么用的?这是为了向库存系统添加物品。你应该记录例外情况或使用e.printStackTrace,而不仅仅是发布反馈消息,如无效条目,这些信息不能提供详细信息来分析问题。谢谢@MarkRotterVeel,我会一直避免。谢谢你的回答,我已经编辑了代码,但在这一行中,请尝试PreparedStatement update=connection.prepareStatementquery,有一个小错误,因为它说找不到变量连接,可能是什么原因problem@Stevoski和你的案子有联系,明白吗?