몬스티티
10
2017-06-16 17:46:26 작성 2017-06-16 17:47:31 수정됨
2
976

DB연동하여 우편번호 검색을 하려고 하는데 오류가 뜹니다


import java.sql.*;
import java.util.*;
import java.awt.EventQueue;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

public class ZipCodeShearch extends JFrame {
	private JPanel jp;
    private JTable table;
    private JComboBox cb;
    private JComboBox cb1;
    private JComboBox cb2;
   
    private Connection conn = null;
    private PreparedStatement ps = null;      
    private ResultSet rs = null;         
    private JScrollPane scroll;
    private JPanel panel;

    public static void main(String[] args) {    
        EventQueue.invokeLater(new Runnable() {
                public void run() {
                       try {
                    	   ZipCodeShearch frame = new ZipCodeShearch();
                               frame.setVisible(true);
                       } catch (Exception e) {
                               e.printStackTrace();
                       }
                }
        });
 }
    
    public ZipCodeShearch() {
    	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	setTitle("도로명 주소를 이용한 우편번호 검색");
    	setBounds(100, 100, 628, 515);
        jp = new JPanel();
        jp.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(jp);
        jp.setLayout(null);
        
        panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "우편번호 검색", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        panel.setBounds(6, 10, 594, 90);
        jp.add(panel);
        panel.setLayout(null);
       
        scroll = new JScrollPane();
        jp.setBounds(12, 153, 588, 340);
        jp.add(scroll);
       
        
        table = new JTable();
        table.setModel(new DefaultTableModel(
                new Object[][] {
                       {" ", " "},
                },
                new String[] {
                       "우편번호", "도로명주소"
                }
        ) {
                boolean[] columnEditables = new boolean[] {
                       false, false
                };
                public boolean isCellEditable(int row, int column) {
                       return columnEditables[column];
                }
        });
        
        scroll.setViewportView(table);
        
        
        //첫번째 콤보박스
        cb = new JComboBox();  
        cb.setBounds(100, 50, 100, 20);
        panel.add(cb);
        cb.addItem("선택하십시오.");
        
        displaySido();
        
       
        
        cb.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
            	if(e.getStateChange()==ItemEvent.SELECTED)
            		selectSido(cb.getSelectedItem().toString());
                  
            	}
        });
        	 cb.setToolTipText("");
   
        	JLabel label = new JLabel("광역시/도");
        	label.setBounds(100, 21, 100, 20);
        	panel.add(label);
        	label.setHorizontalAlignment(SwingConstants.CENTER);
        	
        //두번째 콤보박스
        	
        cb1 = new JComboBox();
        cb1.setBounds(220, 50, 100, 20);
            panel.add(cb1);
           
            JLabel la1 = new JLabel("시/군/구");
            la1.setBounds(220, 21, 100, 20);
            panel.add(la1);
            la1.setHorizontalAlignment(SwingConstants.CENTER);
           
            cb1.addItemListener(new ItemListener() {
                public void itemStateChanged(ItemEvent e) {
                   if(e.getStateChange()==ItemEvent.SELECTED)
                      selectGugun(cb.getSelectedItem().toString(),cb1.getSelectedItem().toString());
                    }
            });
            
         //세번째 콤보박스
         cb2 = new JComboBox();
         cb2.setBounds(340, 50, 100, 20);
         panel.add(cb2);
           
         JLabel la2 = new JLabel("도로명주소");
         la2.setBounds(340, 21, 100, 20);
         panel.add(la2);
         la2.setHorizontalAlignment(SwingConstants.CENTER);
            
         cb2.addItemListener(new ItemListener() {
             public void itemStateChanged(ItemEvent e) {
               if(e.getStateChange()==ItemEvent.SELECTED)
               selectRoadname(cb.getSelectedItem().toString(), cb1.getSelectedItem().toString(), cb2.getSelectedItem().toString());
                }             
        });
         
        //검색 버튼
    	JButton btn = new JButton("검색");
    	btn.setBounds(450, 50, 60, 20);
    	panel.add(btn);
    	btn.addItemListener(new ItemListener() {
    		@Override
			public void itemStateChanged(ItemEvent e) {
    			String sql;
    			if (e.getSource()==cb){
					if(e.getSource()==cb1){
						if(e.getSource()==cb2){
							sql = "select * from bill_zipcode where sido=? and gugun=? and roadname=?";
						}
					else{
						sql = "select * from bill_zipcode where sido=? and gugun=?";
						}
					}
					else{
						sql = "select * from bill_zipcode where sido=?";
					}
				}
				else{
					sql = "select * from bill_zipcode";
				}
    			
    			try {
					ps = conn.prepareStatement(sql);
					rs = ps.executeQuery();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
    			

    		}});
    }

   /* public void searchroadname (String roadname){
   	 ZipCodeDAO con = new ZipCodeDAO();
        con.getConnect();   

        ArrayList<ZipCodeDTO> addressList = con.searchKeyRoadname(roadname);
        Object[][] arrAdd = new Object[addressList.size()][2];
        for(int i = 0 ; i < addressList.size() ; i++){
       	 	 ZipCodeDTO zipcode = addressList.get(i);

        arrAdd[i][0] = zipcode.getZipcd();
        arrAdd[i][1] = zipcode.getRoadname();

               
                table.setModel(new ZipCodeTable(arrAdd));
                
        }             
        con.disconnection();
    }*/
         
         public void displaySido(){
        	 ZipCodeDAO con = new ZipCodeDAO();
             con.getConnect();             
             ArrayList<ZipCodeDTO> sidoList = con.searchSido();
             for(int i = 0 ; i < sidoList.size() ; i++){
            	 ZipCodeDTO zipcode = sidoList.get(i);
                     cb.addItem(zipcode.getSido());
             }             
             con.disconnection();
      }
         
         public void selectSido(String sido){
             System.out.println(sido);
             ZipCodeDAO con = new ZipCodeDAO();

             con.getConnect();             

             ArrayList<ZipCodeDTO> gugunList = con.searchGugun(sido);
             cb1.removeAllItems();
             cb2.removeAllItems();
             cb1.addItem("광역시/도");
             for(int i = 0 ; i < gugunList.size() ; i++){
            	 ZipCodeDTO zipcode = gugunList.get(i);
                     cb1.insertItemAt(zipcode.getGugun(), i);
             }
             table.setModel(new ZipCodeTable());
             con.disconnection();
      }      
         
         public void selectGugun(String sido, String gugun){
             System.out.println(gugun);
             ZipCodeDAO con = new  ZipCodeDAO();
             con.getConnect();              

             ArrayList<ZipCodeDTO> roadnameList = con.searchRoadname(sido, gugun);
             cb2.removeAllItems();
             cb2.addItem("시군구");
             for(int i = 0 ; i < roadnameList.size() ; i++){
            	 ZipCodeDTO zipcode = roadnameList.get(i);
                     cb2.insertItemAt(zipcode.getRoadname(),i);
             }
             table.setModel(new ZipCodeTable());
             con.disconnection();                 
      }
         
         public void selectRoadname(String sido, String gugun, String roadname){
             System.out.println("Selected roadname : " + roadname);
             ZipCodeDAO con = new ZipCodeDAO();

             con.getConnect();                

              ArrayList<ZipCodeDTO> addressList = con.searchAddress(sido, gugun, roadname);
             
              Object[][] arrAdd = new Object[addressList.size()][2];
             
              for(int i = 0 ; i < addressList.size() ; i++){
            	  	  ZipCodeDTO zipcd = addressList.get(i);

                      System.out.println(zipcd.getZipcd() + " " + zipcd.getRoadname() + " ");                      
                      arrAdd[i][0] = zipcd.getZipcd();
                      arrAdd[i][1] = zipcd.getRoadname();

                     
                      table.setModel(new ZipCodeTable(arrAdd));
                      System.out.println("table Setting");
              }
              con.disconnection();
           
		}
     

}
at ZipCodeShearch.selectroadname(ZipCodeShearch.java:241)
at ZipCodeShearch$5.itemStateChanged(ZipCodeShearch.java:131)
at ZipCodeShearch.selectGugun(ZipCodeShearch.java:226)
at ZipCodeShearch$4.itemStateChanged(ZipCodeShearch.java:114)
at ZipCodeShearch.selectSido(ZipCodeShearch.java:210)
at ZipCodeShearch$3.itemStateChanged(ZipCodeShearch.java:89)

인덱스에서 누락된 IN 또는 OUT 매개변수:: 1 라고 오류가 뜨네요.

0
  • 답변 2

  • 아항항하잏이
    77
    2017-06-16 17:55:51
    con.searchAddress(sido, gugun, roadname)

     

    요기서 실행되는 쿼리에 물음표랑 매개변수가 틀린거 아닌가요 

  • siva6
    5k
    2017-06-16 17:58:15

    ?의 값을 세팅하는 부분이 어디인가요?

  • 로그인을 하시면 답변 을 등록할 수 있습니다.