I
I
Ilya2014-01-26 09:10:39
Java
Ilya, 2014-01-26 09:10:39

Why is the query to the database not being executed?

Hello! The problem with the execution of the request, I can not understand what's what! There is a function selectDataOfTable , which receives the selection schema and the table itself as input. Sadness arises when I try to unload data from the VacanciesOfEmployers table (table schema below), when:
- When querying:

Request times
"SELECT VacanciesOfEmployers.id, Employers.name, Employers.contacts, Employers.hr_specialist, Vacancies.name, requirement, minCost, maxCost, placementDate FROM (VacanciesOfEmployers INNER JOIN Employers ON VacanciesOfEmployers.id_employer = Employers.id) INNER JOIN Vacancies ON Vacancies.id = VacanciesOfEmployers.id_vacancy"

Exception: "no such column: VacanciesOfEmployers.id"
- When asked:
Request two
"SELECT Employers.name, Employers.contacts, Employers.hr_specialist, Vacancies.name, requirement, minCost, maxCost, placementDate FROM (VacanciesOfEmployers INNER JOIN Employers ON VacanciesOfEmployers.id_employer = Employers.id) INNER JOIN Vacancies ON Vacancies.id = VacanciesOfEmployers.id_vacancy"

Exception: "no such column: Employers.name"
- When asked:
Request three
"SELECT * FROM (VacanciesOfEmployers INNER JOIN Employers ON VacanciesOfEmployers.id_employer = Employers.id) INNER JOIN Vacancies ON Vacancies.id = VacanciesOfEmployers.id_vacancy"

Exception: "no such column: VacanciesOfEmployers.id_vacancy"
If you make a query to the database through SQLite Expert Personal , then the query is executed in all three options!
selectDataOfTable function
String[] columns = this.getColumnsForTable(select, tableName);
List<Object[]> result = new ArrayList<>();
ResultSet rs = cursor.executeQuery("SELECT "+ select +" FROM "+ tableName +" ORDER BY name ASC");
/** прочитываем значения из RS и заполняем массив в соотвествии со столбцами */
while(rs.next()) {
    Object[] row = new Object[columns.length];
    for (int i=0; i<columns.length; i++) {
        row[i] = rs.getString(columns[i]);
    }
    result.add(row);
}
return result;

Table Schema
[id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[id_employer] INTEGER NOT NULL CONSTRAINT [FK_employers] REFERENCES [Employers]([id]) ON DELETE RESTRICT ON UPDATE RESTRICT,
[id_vacancy] INTEGER NOT NULL CONSTRAINT [FK_vacancy] REFERENCES [Vacancies]([id]) ON DELETE RESTRICT ON UPDATE RESTRICT,
[requirement] TEXT NOT NULL,
[minCost] INTEGER,
[maxCost] INTEGER,
[placementDate] DATE NOT NULL)"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Bespalov, 2014-01-26
@nulldef

Remove the parentheses, they're useless

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question