Error-com.microsoft.sqlserver.jdbc.SQLServerException:关键字“BY”附近的语法不正确

时间:2016-06-13 08:53:25

标签: java

private void UptadeSupplierActionPerformed(java.awt.event.ActionEvent evt) 
{                                               
    try
    {
        Class.forName(driver);  
        Connection con = DriverManager.getConnection(url, user, pass);
        Statement st = con.createStatement();
        ResultSet rec =st.executeQuery("SELECT SupName, SupSurName" +
           "FROM Suppliers" +
           "ORDER BY SupName");

        while(rec.next())
        {
            System.out.println(rec.getString("SupName") + "," + rec.getString("SupSurName") + ".");
        }
        st.close();
    } 
    catch(Exception e)
    {
        System.out.println("Error-" + e.toString());
    }
}                          

1 个答案:

答案 0 :(得分:0)

你像这样连接你的字符串:

"SELECT SupName, SupSurName" + "FROM SUPPLIERS"

这将导致:

SELECT SupName, SupSurNameFROM Suppiers

请注意,您在“SupSurName”和“FROM”之间缺少空格。在字符串之间添加“”(空格)或者只是在每个字符串的末尾添加一个空格。