当我尝试在 Java 中执行查询时遇到问题。当我尝试在 SQL 中将对象添加到我的数据库时,它给了我一个错误,说该指令不发送结果集。当我在 sql server 中执行查询时,它工作正常并插入对象。请帮我。
public void addAlbum(String title, double price, String genre, String date, String home, String image) {
int number = getData().size();
boolean isThere = false;
Statement statement;
for(int i = 0; i < getData().size();i++){
if(getData().get(i).getTitle().equals(title)){
isThere = true;
}
}
if(!isThere){
try{
statement = connexion.createStatement();
String query = "use albums INSERT INTO dbo.Album(Album.artist_number, title, price, genre, date, home, image) VALUES(" + number + ", '" + title + "', " + price + ", '" + genre + "', '" + date + "', '" + home + "', '" + image + "')";
statement.executeQuery(query);
getData().add(new Album(String.valueOf(number),title, price, genre, date, home));
fireTableRowsInserted(getData().size() -1, getData().size() -1);
}catch(SQLException e){
JOptionPane.showMessageDialog(null,
"Error "
+ e.getMessage(), "Result",
JOptionPane.ERROR_MESSAGE);
}
}else{
JOptionPane.showMessageDialog(null,
"There is already an album with this name", "Result",
JOptionPane.ERROR_MESSAGE);
}
}