아마존이라는 클래스에 대한 프로젝트 데이터베이스를 만들었습니다. 이 보고서에서 내가 가장 잘 팔린 제품을 마지막으로 팔린 제품으로 표시하고 싶습니다. 나는 가장 팔린 제품을 가져 와서 그들을 구입 한 모든 고객을 표시하고 싶습니다. 과 디스플레이 및 전자 우편과 그들이 제품을 구입 한 수량을 표시하고 싶습니다. 좋아, 나는 베스트 셀러 상품을 종합적으로 표시 할 수있다. 그리고 첫 번째 행을 얻는 방법을 안다. (두 개 이상의 제품이 같은 수의 판매량을 갖고 있다면 문제가 될 것이다.)하지만, 결과 세트의 첫 번째 테이블에서 제목을 얻을 수는 없다. 다른 쿼리 :/ 누구든지이 문제를 해결할 수 있습니까?결과 집합에서 정보를 가져 오는 동안
void report2 (Connection conn)
throws SQLException, IOException {
String query0 = "select title, SUM (quantityb) AS total from product,buy where id = idb group by title order by total DESC";
String title,title2,name,email,t;
int quan,quanp;
Statement stmt = conn.createStatement();
ResultSet rset0;
System.out.print("\n\n************************************MOST POPULAR PRODUCTS************************************\n");
System.out.print(" TITLE OF THE PRODUCT TOTAL PURCHASED\n"+
"-------------------------------------------- -------------------------\n");
try {
rset0 = stmt.executeQuery(query0);
} catch (SQLException e) {
System.out.println("Problem reading purchases");
while (e != null) {
System.out.println("Message : " + e.getMessage());
e = e.getNextException();
}
return;
}
while (rset0.next())
{
title = rset0.getString(1);
quan = rset0.getInt(2);
System.out.printf("%-108s %-3d \n ",title,quan);
}
PreparedStatement statement = conn.prepareStatement(query0);
statement.setMaxRows(1);
ResultSet rset1 = statement.executeQuery();
while (rset0.next())
{
title2= rset1.getString(1);
}
String query2 = "select
String query1 = "Select fname,email,quantityb"+
"from custumer,product,buy"+
"where email = emailb"+
"and id = idb"+
"and title ='"+title2+"'";
System.out.print("..............................Who Purchased the most popular product.............................\n");
System.out.print("PRODUCT:"+title2+"\n\n");
System.out.print(" FIRST NAME EMAIL QUANTITY\n"+
"--------------------- ----------------------------- ------------------\n");
ResultSet rset2;
try {
rset2= stmt.executeQuery(query1);
} catch (SQLException e) {
System.out.println("Problem reading people");
while (e != null) {
System.out.println("Message : " + e.getMessage());
e = e.getNextException();
}
return;
}
while (rset2.next())
{
name=rset2.getString(1);
email=rset2.getString(2);
quanp=rset2.getInt(3);
System.out.printf("%-8s \t\t\t%-25s\t\t\t %3d \n ",name,email,quanp);
}
stmt.close();
}
결과
commerce.java:405 : 변수 직책 2가 초기화 "제목 = '"+ 직책 2 + "'"않았을 수 있습니다; ^ 1 오류