What is wrong with the code?

There is a table:

try{ statm.execute("CREATE TABLE `player` (`id_player` INT(11) NOT NULL AUTO_INCREMENT, `surname` VARCHAR(85) NOT NULL, " + "`name` VARCHAR(85) NOT NULL, `patronymic` VARCHAR(85) NOT NULL, `birth_date` DATE NOT NULL, `height` int(20) NOT NULL," + "`weight` int(20) NOT NULL, `teamP` VARCHAR(85) NOT NULL," + "`date_pr` DATE NOT NULL, `amplua` VARCHAR (85) NOT NULL, `personal_id` int(11) NOT NULL," + " PRIMARY KEY(id_player))"); statm.executeUpdate("INSERT INTO `player` (`surname`, " + "`name`, `patronymic`, `birth_date`, `height`," + "`weight`, `teamP`," + "`date_pr`, `amplua`, `personal_id`) VALUES ('Arktaev', 'Viktor', 'Vladimirovich', '1990-06-28', " + "'180', '80', 'Spartak', '2015-02-17', 'Offence', '6')," + "('Babakin', 'Sergey', 'Andreevich', '1985-11-15', " + "'182', '76', 'Squirells', '2015-02-18', 'Defence', '4')"); } catch (SQLException e){ Connect.tp_sost.setText("Ошибка create table player"); System.err.println(e); return; } 

There is a DESCRIBE request.

 try{ res = statm.executeQuery("DESCRIBE player"); while(res.next()){ System.out.println(res.getString(1) + "\t" + res.getString(2) + "\t" + res.getString(3) + "\t" + res.getString(4) + "\t" + res.getString(5) + "\t" + res.getString(6) +"\t" + res.getString(7)+ "\t" + res.getString(8) + "\t" + res.getString(9)+ res.getString(10)+ res.getString(11) + "\n"); } System.out.println(); } catch(SQLException e){ Connect.tp_sost.setText("Ошибка player"); System.err.println(e.getMessage()); return; } 

I receive:

** Error player

Column Index out of range, 7> 6. **

  • And what do you think should get those getstring. I somehow doubt that describe returns as many as 11 columns - Mike
  • @Mike they should return info about each column in the table - Alexander Vasilchuk
  • why doubt if they are all created - Alexander Vasilchuk
  • Are @post_zeew attributes columns? 11, means - Alexander Vasilchuk
  • Roughly speaking, DESCRIBE player returns a table with 11 rows and 6 columns, and not vice versa. - post_zeew

1 answer 1

DESCRIBE player gives a description of the table, not a record. In the description of the table there are 6 columns.

SELECT * FROM player; try it.

  • SELECT I do separately, yes; At this stage I want to get a conclusion about the description of the table - Alexander Vasilchuk
  • SELECT works for me, but DESCRIBE - no - Alexander Vasilchuk
  • A table of 6 columns is returned to you (he even wrote you a description of the error), and in the processing of a request you ask as many as 11 columns. Here on request of the 7th column the error also takes off. Try with your hands to write a query in SQL, see what the server is responsible - Tachkin
  • I understand, now I will try - Alexander Vasilchuk