简体   繁体   English

内部联接语句Java

[英]Inner Join Statement Java

The SQL code runs perfectly fine in mysql, and my other statements in this application work but this one saying my table dosn't exist when it clearly does, Made sure all the syntax is right so i don't understand why its not working, My code is posted below 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());
    }
}            

Looks like space or comma issue in your query.The best way to solve it is print the query and try executing the printed query in your sql client. 在查询中看起来像空格或逗号问题。解决该问题的最佳方法是打印查询,然后尝试在sql客户端中执行打印的查询。

looks like comma missing between Prod_Srv_Discount Contracts_Contract_Number 好像Prod_Srv_Discount Contracts_Contract_Number之间缺少逗号

hope this should solve the issue. 希望这能解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM