内部联接声明Java

时间:2015-07-02 03:40:37

标签: java sql exception inner-join

SQL代码在mysql中运行得非常好,而且我在这个应用程序中的其他语句也可以工作,但是这个说明我的表格显然不存在,确保所有语法都正确所以我不明白为什么它不工作,我的代码发布在

下面
 private void salesReportbtnActionPerformed(java.awt.event.ActionEvent evt) {                                               
    try {
        con = DriverManager.getConnection(url, user, password);
        stmt = con.createStatement();
        result = stmt.executeQuery("SELECT Prod_Srv_ID , `The_Organizations_Organization_Name` ,"
                + " `Prod_Srv_Details` , `Prod_Srv_Price` , `Prod_Srv_Discount` `Contracts_Contract_Number` ,"
                + " `Shipment_Completed`\n"
                + "FROM product_and_services\n"
                + "JOIN product_contract_line ON product_and_services.Prod_Srv_ID ="
                + " product_contract_line.Product_and_Services_Prod_Srv_ID");
        int tempName = 4;
        salesReportlist.setText("");
        String Shipres;
        while (result.next()) {
            tempName = tempName + 1;
            int prodID = result.getInt("Prod_Srv_ID");
            String orgName = result.getString("The_Organizations_Organization_Name");
            String Details = result.getString("Prod_Srv_Details");
            double Price = result.getDouble("Prod_Srv_Price");
            double Discount = result.getDouble("Prod_Srv_Discount");
            double contractNum = result.getDouble("Contracts_Contract_Number");
            int Ship = result.getInt("Shipment_Completed");
            if(Ship == 1)
            {
                Shipres = "True";
            }
            else{
                Shipres = "False";
            }
            if (tempName >= 5) {
                salesReportlist.setText(salesReportlist.getText() + "\n" + "   Product ID:   " + prodID + "   Organization Name:   " + orgName + "   Details:   " + Details + "   Price:    " + Price+ "   Discount:    " + Discount + "   Contract Number:    " + contractNum + "   Shipment Completed:    " + Shipres );
            } else {
                JOptionPane.showMessageDialog(null, "Error");
            }
        }
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
    }
}            

1 个答案:

答案 0 :(得分:1)

在查询中看起来像空格或逗号问题。解决它的最佳方法是打印查询并尝试在sql客户端中执行打印查询。

Prod_Srv_Discount Contracts_Contract_Number

之间看起来像逗号一样

希望这可以解决问题。