· 9 years ago · Feb 03, 2017, 10:50 PM
1java.sql.SQLException: Column 'Rock' not found.
2 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
3 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
4 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
5 at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1093)
6 at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5488)
7 at DAO.MusicTypeDAO.getAll(MusicTypeDAO.java:108)
8 at DAO.Main.main(Main.java:18)
9
10public List<MusicType> getAll() {
11 String requestMysql = "SELECT * FROM music_type;";
12 List<MusicType> musicTypes = new ArrayList();
13 PreparedStatement ps;
14 try {
15 ConnectionUtils.getConnection().setAutoCommit(false);
16
17 ps = ConnectionUtils.getConnection().prepareStatement(requestMysql);
18 ResultSet rs = ps.executeQuery();
19 while (rs.next()) {
20 MusicType musicType = new MusicType(rs.getInt("id"), rs.getString(rs.getString("type_name")));
21 musicTypes.add(musicType);
22 }
23
24 ConnectionUtils.getConnection().commit();
25 } catch (SQLException e) {
26 e.printStackTrace();
27 }
28 return musicTypes;
29 }
30
31CREATE database if not exists `users_and_music` ;
32USE users_and_music;
33
34CREATE TABLE address (
35 id INT PRIMARY KEY AUTO_INCREMENT,
36 country VARCHAR(256),
37 street VARCHAR(256),
38 zip INT
39);
40CREATE TABLE role (
41 id INT PRIMARY KEY AUTO_INCREMENT,
42 role_name VARCHAR(256)
43);
44CREATE TABLE music_type (
45 id INT PRIMARY KEY AUTO_INCREMENT,
46 type_name VARCHAR(256)
47);
48
49CREATE TABLE user (
50 id INT NOT NULL AUTO_INCREMENT,
51 role_id INT NOT NULL,
52 firstName VARCHAR(15) DEFAULT NULL,
53 lastName VARCHAR(15) DEFAULT NULL,
54 login VARCHAR(15) DEFAULT NULL,
55 userpassword VARCHAR(20) DEFAULT NULL,
56 age SMALLINT(3) DEFAULT NULL,
57 PRIMARY KEY (`id`),
58 FOREIGN KEY (role_id)
59 REFERENCES role (id)
60);
61
62CREATE TABLE user_music_type (
63 user_id INT NOT NULL,
64 music_type_id INT NOT NULL,
65 PRIMARY KEY(user_id,music_type_id ),
66 FOREIGN KEY (user_id)
67 REFERENCES user (id),
68 FOREIGN KEY (music_type_id)
69 REFERENCES music_type (id)
70);