Java 怎么将从数据库查询到的信息返回到界面的面板上
就是,我做的类似于QQ空间的说说的那种,我觉得在界面上是面板一块一块分布的,但是我现在返回的是一个表,请大家告诉我,怎么改成面板publicvoidrefresh(Arr...
就是,我做的类似于QQ空间的说说的那种,我觉得在界面上是面板一块一块分布的,但是我现在返回的是一个表,请大家告诉我,怎么改成面板
public void refresh(ArrayList d) {
String[][] data = new String[d.size()][];
for (int i = 0; i < d.size(); i++) {
Object u = d.get(i);
data[i] = u.toString().split(",");
}
model.setDataVector(data, columns);
model.fireTableDataChanged();
}
@Override
public ArrayList<mood> selectMood() {
// TODO Auto-generated method stub
mood moods = null;
Statement st = null;
ResultSet rs = null;
ArrayList<mood> list = new ArrayList<mood>();
try {
st = DBTool.getConnection().createStatement();
String sql = "select m_addr,m_id,m_head,m_time,m_content,p_id from mood";
rs = st.executeQuery(sql);
while (rs.next()) {
String m_addr = rs.getString(1);
int m_id = rs.getInt(2);
String m_head = rs.getString(3);
String m_time = rs.getString(4);
String m_content = rs.getString(5);
int p_id = rs.getInt(6);
moods = new mood(m_addr,m_id + "",m_time, m_head,m_content, p_id+ "");
list.add(moods);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
st.close();
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
} 展开
public void refresh(ArrayList d) {
String[][] data = new String[d.size()][];
for (int i = 0; i < d.size(); i++) {
Object u = d.get(i);
data[i] = u.toString().split(",");
}
model.setDataVector(data, columns);
model.fireTableDataChanged();
}
@Override
public ArrayList<mood> selectMood() {
// TODO Auto-generated method stub
mood moods = null;
Statement st = null;
ResultSet rs = null;
ArrayList<mood> list = new ArrayList<mood>();
try {
st = DBTool.getConnection().createStatement();
String sql = "select m_addr,m_id,m_head,m_time,m_content,p_id from mood";
rs = st.executeQuery(sql);
while (rs.next()) {
String m_addr = rs.getString(1);
int m_id = rs.getInt(2);
String m_head = rs.getString(3);
String m_time = rs.getString(4);
String m_content = rs.getString(5);
int p_id = rs.getInt(6);
moods = new mood(m_addr,m_id + "",m_time, m_head,m_content, p_id+ "");
list.add(moods);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
st.close();
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询