Hello, members of the forum.

Help, who can, make a sql student a request to select a table entry by its number. The request (compiled by me) looks like this:

try { String sqlReqest = "select * from "+strTableName+" where id = [3,5,7]"; statement.executeUpdate(sqlReqest); // SELECT * FROM mytable WHERE id = [2, 5, 11] } catch(Exception ex) 

It returns a permanent error: too few parameters are required 2. When I specify a single number in the parameters without [], then an error: too few parameters are required 1. Tell me the correct query record.

Is there any way to determine the number of records in a table?

    2 answers 2

    Every day I see something new) Kick me hard if, as it is, you can do everything from above.

    The id is not a "record number". This is (accepted but not required) a unique entry code in the table.

    Secondly, nowhere is it said that it is solid. It was 1,2,3,4. 2 removed and became 1,3,4. And in general, to restore this is not recommended.

    There are two options. Either the client must skip the number of records, or use something like the limit construct in mysql. But it works only on the interval.

    If you need a sample by id, then:

     SELECT * FROM mytable WHERE id in (2, 5, 11) 
    • The record number is transferred to the procedure (from the possible range) and this procedure should present the value of this record to the user on the screen. Here's how to formulate a request, I can't understand ... private void ShowCurrentTableRecord (int RecordNumber) {if (bCreatedConnection) {try {String sqlReqest = "SELECT * FROM" + strTableName + "WHERE id IN (1)"; statement.executeUpdate (sqlReqest); tfQuestionText.setText (resultSet.getString (1)); tfFirstAnswer.setText (resultSet.getString (2)); ...} - pj-infest
    • Brrr .... String sqlReqest = "SELECT * FROM" + strTableName + "WHERE id IN (" + RecordNumber + ")"; ? In general, this question is usually used in the following question: select Question. *, Answer.
     SELECT * FROM mytable WHERE id IN (2, 5, 11); SELECT COUNT(id) FROM mytable;