我爲我的班級創建了一個名爲amazon的項目數據庫。 在這份報告中,我想展示最好的產品和最後的產品。 我想要得到最高級的selled產品,並顯示所有購買它們的客戶 ,並顯示它們的電子郵件和他們對該產品進行的量化。 好吧,我可以總是展示最好的selled產品。而且我知道如何獲得第一排(如果兩個或更多產品的銷售數量相同,我會遇到問題),但我不能只從結果集中的第一張表中獲得標題,另一個查詢:/ 任何人都可以幫我解決這個問題嗎?從結果集中獲取信息,而
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();
}
RESULT
commerce.java:405:可變TITLE2可能沒有被初始化 「和標題= ' 」+ TITLE2 +「'」; ^ 1錯誤