Sqlite列确定错误

时间:2015-08-04 17:19:24

标签: java mysql sqlite jdbc jcombobox

我试图从J combo Box中选择并使用它来从数据库中查找表格。但反而出现了错误:

The thing that shows

我的代码:

JButton btnGo = new JButton("Go!");
    btnGo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Connection conni = null;
            ResultSet rs=null;
            PreparedStatement pst=null;
            try{
                Class.forName("org.sqlite.JDBC");
                conni  = DriverManager.getConnection("jdbc:sqlite://C://Users//Asus//Dropbox//TireShop.sqlite");
                String x = comboBox.getSelectedItem().toString();
                String sql="select * from " + x;


                pst=conni.prepareStatement(sql);
                rs=pst.executeQuery();
                while(rs.next()){
                    String name = rs.getString("Namet");

                    nameofguy.setText(rs.getString(name));
                }

            }catch(Exception i){
                JOptionPane.showMessageDialog(null, i);

            }

我正在寻找餐桌..但它说无法找到专栏。

1 个答案:

答案 0 :(得分:1)

这是你的问题

File -> Invalidate Cache/Restart

取而代之的是

while(rs.next()){
   String name = rs.getString("Namet");
   //rs.getString returns Ayaan. So value of name is "Ayaan"
   nameofguy.setText(rs.getString(name));
   // Youre trying to get the value corresponding to the column Ayaan here
   //This is why the exception is thrown as there is no column called Ayaan
   }