2012-11-28 5 views
0

아마존이라는 클래스에 대한 프로젝트 데이터베이스를 만들었습니다. 이 보고서에서 내가 가장 잘 팔린 제품을 마지막으로 팔린 제품으로 표시하고 싶습니다. 나는 가장 팔린 제품을 가져 와서 그들을 구입 한 모든 고객을 표시하고 싶습니다. 과 디스플레이 및 전자 우편과 그들이 제품을 구입 한 수량을 표시하고 싶습니다. 좋아, 나는 베스트 셀러 상품을 종합적으로 표시 할 수있다. 그리고 첫 번째 행을 얻는 방법을 안다. (두 개 이상의 제품이 같은 수의 판매량을 갖고 있다면 문제가 될 것이다.)하지만, 결과 세트의 첫 번째 테이블에서 제목을 얻을 수는 없다. 다른 쿼리 :/ 누구든지이 문제를 해결할 수 있습니까?결과 집합에서 정보를 가져 오는 동안

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 오류

답변

0

이것은 숙제이거나 운동으로 보입니다. 당신이

String title="", title2="", name="", email="", t="";title2

변경합니다

String title,title2,name,email,t;을 포함한 문자열 변수 중 하나를 초기화하지 않았기 때문에

variable title2 might not have been initialized 

이다.

둘째,

String query2 = "select 

이 불완전하고 인용하고 세미콜론을 종료 뭔가 의미있는 값이어야합니다. 보조 노트에

String query2 = "select * from tblName";처럼

,
항상 질문에 전체 오류 스택을 제공합니다.

관련 문제