从DB获取时无效的列索引异常

时间:2014-03-15 12:39:50

标签: java jdbc

有人可以告诉为什么代码在获取数据时显示Invalid column index exception。这是我插入记录时顺利运行的代码。但是在我尝试检索异常时显示异常。这是代码。

 public class Photoss extends JFrame implements ActionListener
 {
 JLabel l1,l2,l3;
 JButton b1,b2;
 ImageIcon i;
 JTextArea ta1,ta2;
 Photoss()
 {
 setSize(500,500);
 setVisible(true);
 setLayout(new FlowLayout());

 }
 public void actionPerformed(ActionEvent ae)
 {
 String sw="";

  if
  {
    try{

        String st=ta1.getText();
   Class.forName("oracle.jdbc.OracleDriver");
   Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:xe","system","kanishkag");
   Statement smt=conn.createStatement();
   ResultSet rs=smt.executeQuery("select * from PICTURES where Name='"+st+"'");
   while(rs.next())
   {sw=rs.getString(2);
    }
   if(st.equals(sw))
   {l2.setIcon((Icon) (Image) rs.getBlob(1));
   ta1.setText(rs.getString(2));
   ta2.setText(rs.getString(3));
   }
   }
   catch(Exception e1)
   {
    System.out.println(""+e1);
    }
    }
    }
    public static void main(String[] args) {

    new Photoss();
     }

     }

请帮帮我!!!

0 个答案:

没有答案