java - Sqlite 列确定错误

标签 java mysql sqlite jdbc jcombobox

我正在尝试从 J 组合框中进行选择,并使用它从数据库中查找表。但出现了错误:

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);

            }

我正在搜索表格..但它说找不到列。

最佳答案

这就是你的问题

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
   }

相反

while(rs.next()){
   String name = rs.getString("Namet");
   nameofguy.setText(name);
   }

关于java - Sqlite 列确定错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31815472/

相关文章:

java - 逐列写入 CSV 文件

java - 通过 Java 使用 Apple 推送通知服务

Mysql 返回 0 总和不为空

java - 查询数据库记录中几乎相似的匹配字符串值

ruby-on-rails - 如何重新初始化 ruby​​ on Rails 项目

c# - 使用 C# 查询 SQlite 数据库时出现 ConstraintException

java - java中的任务栏弹出菜单

java - Swt 调整 Composite 大小但不调整窗口大小

mysql - 如何在子查询中获取Mysql COUNT

android - SQLiteCantOpenDatabaseException : unknown error (code 14): Could not open database (Only when unit testing the app)