저는 java에서 새내! mysql에서 데이터를 가져 와서 Jlist (Jlist name : JLISTF)에 표시 할 수있는 방법 vector와 모델이 혼동 스럽다.mysql에서 jList로 데이터를 가져 오는 방법은 무엇입니까?
:당신에게
코드를 감사 아래
내 JFrame의의 사진입니다노란색 부분은 JList의 의미와는 이름 JLISTF 내가 MySQL의에서 데이터를 표시 할 입니다입니다
public class Inventory extends javax.swing.JFrame {
Connection connect = null;
ResultSet rs = null;
PreparedStatement pst = null;
ResultSet rs2 = null;
public void populateJList(JList ItemList, String query, Connection connection) throws SQLException
{
DefaultListModel model = new DefaultListModel(); //create a new list model
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query); //run your query
while (resultSet.next()) //go through each row that your query returns
{
String ItemList2 = resultSet.getString("ItemCode"); //get the element in column "item_code"
model.addElement(ItemList2); //add each item to the model
}
ItemList.setModel(model);
resultSet.close();
statement.close();
}
public Inventory() {..}
private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) { ......}
private void saveButton3ActionPerformed(java.awt.event.ActionEvent evt) {
String inventcodef = inventCodeField.getText();
try{.........}
catch()
{...........}
}
[의미하는 javax.swing.JList] (http://docs.oracle.com/javase/6/docs/api/javax/swing/JList.html)? 정확히 당신이 이해하지 못하는 것은 - MySQL 데이터베이스 통합 또는 Swing 기반의 UI 구현입니까? – home
JList를 mysql에 채우고 싶지만 시작하는 방법을 모르겠다. – mix
@home 나는 JList를 채우는 방법을 이해하지 못하기 때문에 대체 할 변수를 모른다. 튜토리얼이 있지만 사용 된 변수를 실제로 설명하지는 않습니다. 예를 들어, JLISTF 인 JLIST 변수 이름으로 코드를 대체 할 위치에 제공 한 링크에서 – mix