我试图在多表上使用mysql在javafx中使用select语句

时间:2017-04-20 16:47:42

标签: java mysql

我有6张桌子我选择的数据来自doginfo,dogat,sires,dams,owner和coowners。每个表都有一个PK,每个表都有一个dogid字段。 dogid字段标识个体狗,其他字段保存可以应用于任何狗的重复信息,即许多狗可以具有相同的颜色。我已经验证我的select语句适用于MySQL,我现在正试图让它在javafx中工作。

我的选择语句如下所示:

SELECT doginfo.dogid, doginfo.regnum, doginfo.regname, doginfo.whelpdate, 
   dogat.breed, dogat.sex, dogat.color, sires.sireregname, 
   sires.sireregnum, dams.damregname, dams.damregnum, owners.firstname, 
   owners.lastname, coowners.coownernames, owners.address1, 
   owners.address2, owners.city, owners.zip, doginfo.dna, owners.htel, 
   owners.cell, doginfo.notes
FROM doginfo 
   LEFT JOIN dogat 
       ON doginfo.dogid = dogat.dogid
   LEFT JOIN sires 
       ON doginfo.dogid = sires.dogid
   LEFT JOIN dams 
       ON doginfo.dogid = dams.dogid
   LEFT JOIN owners 
       ON doginfo.dogid = owners.dogid
   LEFT JOIN coowners 
       ON doginfo.dogid = coowners.dogid

我的代码如下

    ResultSet myRs = myStmt.executeQuery("SELECT doginfo.dogid,   doginfo.regnum, doginfo.regname, doginfo.whelpdate, dogat.breed, dogat.sex, dogat.color, sires.sireregname, 
+ " sires.sireregnum, dams.damregname, dams.damregnum, owners.firstname, owners.lastname, coowners.coownernames, owners.address1,"
+ "owners.address2, owners.city, owners.zip, doginfo.dna, owners.htel, owners.cell, doginfo.notes "
+ "FROM doginfo  LEFT JOIN dogat" 
+ ON doginfo.dogid = dogat.dogid"
+ LEFT JOIN sires" 
+ ON doginfo.dogid = sires.dogid"
+ LEFT JOIN dams "
+ ON doginfo.dogid = dams.dogid"
+ LEFT JOIN owners "
+ ON doginfo.dogid = owners.dogid"
+ LEFT JOIN coowners"
+ ON doginfo.dogid = coowners.dogid);

从ON doginfo.dogid = dogat.dogid开始我收到错误消息')'预期 找不到标志 符号变量doginfo location class FXMLDocumentController

unclosed string literal

有人能引导我朝着正确的方向前进吗?

1 个答案:

答案 0 :(得分:0)

您在FROM

后的每一行都缺少引号
ResultSet myRs = myStmt.executeQuery("SELECT doginfo.dogid, doginfo.regnum, doginfo.regname, doginfo.whelpdate, dogat.breed, dogat.sex, dogat.color, sires.sireregname, "
+ " sires.sireregnum, dams.damregname, dams.damregnum, owners.firstname, owners.lastname, coowners.coownernames, owners.address1,"
+ " owners.address2, owners.city, owners.zip, doginfo.dna, owners.htel, owners.cell, doginfo.notes "
+ " FROM doginfo  LEFT JOIN dogat" 
+ " ON doginfo.dogid = dogat.dogid"
+ " LEFT JOIN sires" 
+ " ON doginfo.dogid = sires.dogid"
+ " LEFT JOIN dams "
+ " ON doginfo.dogid = dams.dogid"
+ " LEFT JOIN owners "
+ " ON doginfo.dogid = owners.dogid"
+ " LEFT JOIN coowners"
+ " ON doginfo.dogid = coowners.dogid");