我想從我的sql數據庫中只提取一個數據在java中。我試圖使用resultSet,但是當我想將第一行提取到一個int Variables時,它說resultSet沒有內容。Java的sql結果集沒有數據
這裏是我的代碼
try {
statement = connexion.createStatement();
statementArtist = connexion.createStatement();
String artist = "Mac Miller";
ResultSet resultat = statement.executeQuery("USE albums SELECT Album.numero_artist FROM Album INNER JOIN Artist ON Album.num_artist = Artiste.num_artist where name like '"+artist+"'");
int result = resultat.getInt(1); // Here is the problem
String query = "USE albums INSERT INTO dbo.Album(Album.num_artist, title, price, genre, date, home, image) VALUES("
+ result
+ ", '"
+ title
+ "', "
+ price
+ ", '"
+ genre
+ "', '"
+ date
+ "', '"
+ home
+ "', '"
+ image
+ "')";
statement.executeUpdate(query);
哦,非常感謝我的錯誤!!我忘了.next() – Sebastien