Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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选择查询SQL语法中有错误_Java_Mysql - Fatal编程技术网

Java选择查询SQL语法中有错误

Java选择查询SQL语法中有错误,java,mysql,Java,Mysql,我得到以下错误 您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“日期=”2015-04-26“ORDER BY TraceNum”附近使用的正确语法 这就是问题所在 "SELECT Name, sporecount.* FROM sporesfungi INNER JOIN sporecount ON sporesfungi.IDSpore = sporecount.IDSpore WHERE Date = ? ORDER BY TraceNum"; 如果删除WHER

我得到以下错误

您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第1行“日期=”2015-04-26“ORDER BY TraceNum”附近使用的正确语法

这就是问题所在

"SELECT Name, sporecount.* FROM sporesfungi INNER JOIN sporecount ON sporesfungi.IDSpore = sporecount.IDSpore WHERE Date = ? ORDER BY TraceNum";
如果删除WHERE子句,查询就可以正常工作

这是完整的代码

public void exportToExcel(String date) throws IOException, BiffException, 
 WriteException, SQLException, ParseException{
 Db_Connect  connection = new Db_Connect();
 conn = connection.connect();



 String originalFile = "C:\\Users\\Geni\\Desktop\\Book1-Template-new.xls";   
 date = date.replace("/", "-");
 SimpleDateFormat myDate = new SimpleDateFormat("yyyy-MM-dd");

 try{
        Workbook original = Workbook.getWorkbook(new File(originalFile));
        WritableWorkbook copy = Workbook.createWorkbook(new File(date+".xls"), original);

        java.util.Date format = myDate.parse(date);
        java.sql.Date newDate = new java.sql.Date(format.getTime());

        String sql = "SELECT Name, sporecount.* FROM sporesfungi "
        + "INNER JOIN sporecount ON sporesfungi.IDSpore = sporecount.IDSpore"
                + "WHERE Date = ? ORDER BY TraceNum";

        PreparedStatement statement = conn.prepareStatement(sql);
        statement.setDate(1, newDate);
        rs = statement.executeQuery();
        /*stmt = conn.createStatement();
        rs = stmt.executeQuery(sql);*/


        WritableSheet sheet = copy.getSheet(0);
        WritableCell cell;
        String spore;

        while(rs.next()){
            for(int i = 2; i < 64 ;i++){
                cell = sheet.getWritableCell(1,i);
                spore =  cell.getContents();
                if(rs.getString("Name").equals(spore)){
                   Number l1 = new Number(14-rs.getInt("TraceNum"),i,rs.getInt("Amount")) ;
                   sheet.addCell(l1);

                    }

            }
        }


        copy.write();
        copy.close();
        original.close();
    }
    catch (BiffException | IOException e) {
    }


}

WHERE前面没有空格。

根据代码示例判断,WHERE前面需要空格OMG无法相信它这么简单,谢谢你,它成功了!添加为答案,以便正确标记。