2017-12-27 25 views
-3
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","password"); 
System.out.println("Connected database successfully..."); 
PreparedStatement ps = con.prepareStatement("select * from web");   
ResultSet rs = ps.executeQuery();     
ArrayList<String> v = new ArrayList<>(); 
while (rs.next()) { 
String s = rs.getString(1);        
v.add(s);  
} 
bx = new JComboBox(v); 
bx.setBounds(150, 20, 200, 20); 
f.add(bx); 
} 

나는 다음과 같은 컴파일 오류가JComboBox 객체를 만들 때 왜이 컴파일 오류가 발생합니까?

the constructor jcombobox(string) is undefined

+0

존재하지 않는 생성자를 호출하기 때문에 추가해야합니다. 이것은 ArrayList와 관련이 없으며 JComboBox와 관련이 없습니다. – Stultuske

+0

@Kim 인라인 이미지로 사용할 수있는 인라인 이미지 만 제공 할 수 있습니까? 그 편집이 지금 어떻게 도움이됩니까? – Tom

답변

0

당신은 거의있다 "생성자 JComboBox에 (ArrayList를 < 문자열 >는) 정의되지 않는다"! JCombobox는 인수를 문자열 배열로 사용합니다. 당신은 그것을 변환하거나 수동으로

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root","password"); 
System.out.println("Connected database successfully..."); 
PreparedStatement ps = con.prepareStatement("select * from web");   

ResultSet rs = ps.executeQuery();     
bx = new JComboBox(); 
while (rs.next()) 
{ 
    String s = rs.getString(1);        
    bx.addItem(s);  
} 


bx.setBounds(150, 20, 200, 20); 
f.add(bx); 

}