0

このMySQLクエリがあります

SELECT 
    kompetence.kompetence_odlisujici_subcategories.nazev as odlisujici_nazev, 
    tolerovana, 
    zadana, 
    aktualni
FROM kompetence_odlisujici, kompetence.kompetence_odlisujici_subcategories
WHERE kompetence_odlisujici.os_cislo_zamestnanec = ? 
AND tolerovana <> 0 
AND zadana <> 0 
AND aktualni <> 0 
AND year = ? 
AND IPR.kompetence_odlisujici.active = 1
AND kompetence.kompetence_odlisujici_subcategories.id = PR.kompetence_odlisujici.id_odlisujici_subcategory

MySQL Workbenchで試してみると問題なく動作しますが、Javaコードで使用しようとするとこのエラーが発生します

SQLException :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE kompetence_odlisujici.os_cislo_zamestnanec = '123456' AND tolerovana <> 0 ' at line 1

私は何を間違っていますか?

助けてくれてありがとう。

Javaコードを編集

DataSourcePool dspService = sling.getService(DataSourcePool.class);
DataSource dsMySql = (DataSource) dspService.getDataSource("myConnection");
PreparedStatement preparedStatement = null;
if(dsMySql != null){
String sqlQuery = "SELECT kompetence.kompetence_odlisujici_subcategories.nazev as odlisujici_nazev, tolerovana, zadana, aktualni"+
                "FROM IPR.kompetence_odlisujici, kompetence.kompetence_odlisujici_subcategories "+
                "WHERE IPR.kompetence_odlisujici.os_cislo_zamestnanec = ? AND tolerovana <> 0 AND zadana <> 0 AND aktualni <> 0 AND year = ? AND IPR.kompetence_odlisujici.active = 1"+
                "AND kompetence.kompetence_odlisujici_subcategories.id = IPR.kompetence_odlisujici.id_odlisujici_subcategory";
  Connection mySqlConnection = mySqlConnection = dsMySql.getConnection();
    preparedStatement = mySqlConnection.prepareStatement(sqlQuery);
  String workingUser = this.getWorkingUser();
  int year = Calendar.getInstance().get(Calendar.YEAR);
    preparedStatement.setString(1, workingUser);
    preparedStatement.setInt(2, year);
  ResultSet resultSet = preparedStatement.executeQuery();
  resultSet.last();
    int count = resultSet.getRow();
    resultSet.beforeFirst();
  /*
  parse result set here
  */
}
4

1 に答える 1