자바에서 내 sql 데이터베이스의 데이터를 하나만 추출하려고합니다. 내가 resultSet을 사용하려고했지만 int 변수에 첫 번째 행을 exctract하려는 경우 결과 집합에 내용이 없습니다. 여기 Java sql ResultSet에 데이터가 없음
당신을 "이동"로 설정 결과에next()
메소드를 호출해야 내 코드
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