게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
결국 db갱신 문제를 해결 못하고 코드를 첨부합니다...ㅜㅜ
게시물ID : programmer_14928짧은주소 복사하기
작성자 : 안녕밀라노
추천 : 0
조회수 : 747회
댓글수 : 2개
등록시간 : 2015/12/11 21:10:32
옵션
  • 본인삭제금지
class variable extends JPanel {

public int N = 1;
public int i = 1;
public boolean co1, co2 = false;

public JTable jtb = new JTable();
private JScrollPane jsp1;

public Connection con;
public PreparedStatement pstmt;
public ResultSet rs;
public Connection con2;
public PreparedStatement pstmt2;
public ResultSet rs2;
public Connection con3;
public PreparedStatement pstmt3;
public ResultSet rs3;
public String RealTimeOrder[] = { "번호", "상품 이름", "가격", "개수" };
public DefaultTableModel model = new DefaultTableModel(RealTimeOrder, 0) {
private static final long serialVersionUID = 1L;

public boolean isCellEditable(int row, int column) {
return false;
}
};

}

class jp1 extends variable {

private JScrollPane jsp1;

public jp1() {

try {
UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
} catch (Exception e) {
System.out.println(e);
}

setLayout(null);
setSize(430, 730);

variable t1 = new variable();
variable t2 = new variable();
variable t3 = new variable();

        jtb = new JTable(model);
        jtb.getTableHeader().setReorderingAllowed(false);
        jtb.getTableHeader().setResizingAllowed(false);
        jtb.putClientProperty("Quaqua.Table.style", "striped");

jsp1 = new JScrollPane(jtb);
jsp1.setSize(430, 635);
jsp1.setLocation(0, 15);
jsp1.setVisible(true);
add(jsp1);

}

}

class jpn11 extends variable {

public JButton jbt10101 ;
GridBagConstraints c;

public jpn11() {

GridBagLayout gridbag = new GridBagLayout();
setLayout(gridbag);
c = new GridBagConstraints();
c.weightx = 1.0;
c.weighty = 1.0;

c.fill = GridBagConstraints.CENTER;
setPreferredSize(new Dimension(600, 1000));

layout(jbt10101 = new JButton(new ImageIcon("C:\\Program Files\\Java\\image\\10101.png")), 0, 0, 1, 1);


jbt10101.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
BtnEvent();
}
});

jbt10101.setBackground(Color.white);
jbt10102.setBackground(Color.white);
jbt10103.setBackground(Color.white);
jbt10104.setBackground(Color.white);
jbt10105.setBackground(Color.white);
jbt10106.setBackground(Color.white);
jbt10107.setBackground(Color.white);
jbt10108.setBackground(Color.white);
jbt10109.setBackground(Color.white);
jbt10110.setBackground(Color.white);
jbt10111.setBackground(Color.white);
jbt10112.setBackground(Color.white);
jbt10113.setBackground(Color.white);
jbt10114.setBackground(Color.white);
jbt10115.setBackground(Color.white);
jbt10116.setBackground(Color.white);
jbt10117.setBackground(Color.white);

}

public void layout(Component obj, int x, int y, int width, int height) {
c.gridx = x;
c.gridy = y;
c.gridwidth = width;
c.gridheight = height;
add(obj, c);
}

private void showtable() {
String query = "SELECT * FROM rtorder";
try {
Class.forName(driver);
con = DriverManager.getConnection(url, "root", "");
pstmt = con.prepareStatement(query);
rs = pstmt.executeQuery();
while (rs.next()) {
model.addRow(new Object[] { rs.getString("No"), rs.getString("od_sgname"), rs.getString("od_price"),
rs.getString("count") });
}
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
rs.close();
pstmt.close();
con.close();
} catch (Exception e2) {
}
}
}

public void BtnEvent() {
String query = "INSERT INTO rtorder(od_sgname,od_price) SELECT sgname,rprice FROM salegoods WHERE sgcode= '10101' ";
String query2 = "UPDATE rtorder SET No = ? , count = ? WHERE od_sgname = (SELECT sgname FROM salegoods WHERE sgcode ='10101') ";
if (co1 == false) {
try {
Class.forName(driver);
con = DriverManager.getConnection(url, "root", "");
con2 = DriverManager.getConnection(url, "root", "");
pstmt = con.prepareStatement(query);
pstmt2 = con.prepareStatement(query2);

pstmt2.setInt(1, N);
pstmt2.setInt(2, i);

pstmt.executeUpdate();
pstmt2.executeUpdate();

} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
try {
pstmt.close();
con.close();
pstmt2.close();
con2.close();
} catch (Exception e2) {
System.out.println(e2.getMessage());
}
}
N += 1;
co1 = true;

model.setRowCount(0);
showtable();
} else {
String query3 = "UPDATE rtorder SET COUNT = COUNT + 1 WHERE od_sgname = (SELECT sgname FROM salegoods WHERE sgcode ='10101')";
try {
Class.forName(driver);
con = DriverManager.getConnection(url, "root", "");
pstmt3 = con.prepareStatement(query3);
pstmt3.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
}
model.setRowCount(0);
showtable();
}
}
}

이런식으로 코드를 짜서 
맨위의 variable 클래스에다가 전체적으로 사용하는 변수들 선언하였고
jp1에서 테이블 생성하고 jpn11은 jtp위에 올라간 패널입니다.
jpn11의 버튼을 누르면 jp1의 테이블이 갱신되게끔
showtable을 만들고 각 버튼 이벤트에 들어가게
model.setRowCount(0);  showtable();
를 넣었습니다. 그런데 showtable이 jpn11에서는 갱신 되지 않고
jp1에 showtable을 생성하고 재시작하면 갱신 화면이 보이긴 합니다.
쿼리는 잘못 되지 않은거 같은데 어떤 부분이 이상이 있는건지 화면이 갱신이 안되서.... 감을 못잡겠어서 코드와 함께 질문드렸습니다.
반복적인 질문에 죄송합니다. 약 3일간 이 파트만 찾긴했는데... 제 구글링에 한계인거 같아서 질문 드렸습니다.
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호