static String clname[] = {"No", "이름", "가격", "컨셉", "스타일", "국내/해외"};
static DefaultTableModel model = new DefaultTableModel(clname, 0);
public static javax.swing.JTable resTable;
resTable = new javax.swing.JTable(model);
private static void getQueryTest() {
Connection con = getConnection();
PreparedStatement pstmt = null;
ResultSet rs;
String sql = "select * from travel_db";
try {
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
int row = 1;
while (rs.next()) {
Vector record = new Vector();
record.add(Integer.toString(row++)); // 넘버링
record.add(rs.getString("name")); // 컬럼 명이 name인거
record.add(rs.getString("price"));
record.add(rs.getString("place"));
record.add(rs.getString("style"));
record.add(rs.getString("DomORFor"));
model.addRow(record);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
private static Connection getConnection() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/travelinfo", "root", "ㅇㅇㅇㅇ");
} catch (Exception e) {
e.printStackTrace();
try {
conn.close();
} catch (Exception ee) {
}
conn = null;
}
return conn;
}
'콤퓨타 > JAVA' 카테고리의 다른 글
[GUI] Panel에 이미지 띄우기 (0) | 2013.02.20 |
---|---|
NetBeans 7.0 and 7.1 UML plugin (0) | 2013.02.20 |
자바 디컴파일러 (0) | 2013.02.20 |
hashmap 관련 (0) | 2013.02.20 |
빈 줄 인식 (0) | 2013.02.20 |
댓글