제가 구현하려고 하는것은 영화예매 프로그램에서 예매내역을 취소하는 것입니다.
데이터베이스의 내용을 모두 조회하는 기능과 검색하는 기능은 모두 구현해냈습니다.
(java 의 jtable에서 database를 표현했습니다)
제가 추가기능으로 조회가 된 jtable위에 하나의 row를 선택해 오른쪽클릭을 하고,
예매 취소를 누르면 database에 RE항목의 "예매"를 "취소"로 바꾸고 다시 조회하고 싶습니다.
(지금 현재 질문하고 싶은 부분입니다.)
////////코드입니다
private void Cancel() { //db에서 RE를 '취소'로 바꾼 뒤, 테이블 조회 시키기
//table row 선택하기
javax.swing.table.DefaultTableModel dtm=(javax.swing.table.DefaultTableModel)table.getModel();
int selectedRow=table.getSelectedRow();
String selectedValue=(String)dtm.getValueAt(selectedRow,0);
System.out.println(selectedValue);
try{
//JTable 내용제거
for(int i=model.getRowCount()-1;i>=0;i--) {
model.removeRow(i);
}
Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/java","root","1234");
//취소로 변경하는 명령문
PreparedStatement ps=(PreparedStatement)conn.prepareStatement("update book_mv set RE='취소' where selectedValue RE=?");
ResultSet rs=ps.executeQuery();
//다시 jtable에 표시하는 명령문
ps=(PreparedStatement)conn.prepareStatement("select*from book_mv");
rs=ps.executeQuery();
while(rs.next()) {
String[] row=new String[7];
row[0]=rs.getString("MOVIE");
row[1]=rs.getString("DATE");
row[2]=rs.getString("TIME");
row[3]=rs.getString("PERSON");
row[4]=rs.getString("NUM");
row[5]=rs.getString("SEAT");
row[6]=rs.getString("RE");
model.addRow(row);
}
}catch(SQLException e) {
e.printStackTrace();
}
java에서의 문법적 오류는 없지만 직접 오른쪽클릭 후, '예매취소'를 실행하려고 하면
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:998)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:937)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:872)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:472)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
at project_mv.movie$JPanel3.Cancel(movie_1.java:984)
at project_mv.movie$JPanel3.actionPerformed(movie_1.java:957)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
위와 같은 오류들이 뜹니다.
ResultSet rs=ps.executeQuery(); 이 부분이 오류가 뜨네요.
오류 검색을 하고 알아보던 중 update를 하는 경우에는 executeUpdate()를 써야한다는 글을 보긴했습니다.
그런데 그렇게 한다 하더라도 제대로 실행되지 않았고, 잘못된건 알겠는데 어떻게 해야할지 아무리 검색을 해도 안나와서
이렇게 글을 씁니다 ㅠㅠ
도와주세요!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|