使用Java GUI从SQLite中的表返回列名 [英] Returning column names from table in SQLite using Java GUI

查看:249
本文介绍了使用Java GUI从SQLite中的表返回列名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从表中获取列名,唯一的区别是我创建了一个函数,根据txtbox中的用户条目创建新列。因此,例如,如果用户输入3,则列将被命名为Sezonalni_utjecaj_3。现在,当你看到那个例子时,我需要创建一个返回列名的查询,这样我就可以将它们放在我的组合框中,所以每当我输入一个新列时,列的名称就会放在组合框内(列名有一些东西)共同的,那就是Sezonalni_utjecaj_,但我也有其他专栏,不仅仅是名字里面有Sezonalni_utjecaj_,但我不需要他们的名字。)

I need to get column names from table, only difference is that I made a function that makes new column depending on users entry in txtbox. So for example if a user enters "3", column would be named "Sezonalni_utjecaj_3". Now when you saw that example I need to make a query that returns column names so I can put them inside my combobox, so everytime I enter a new column, the name of the column would be placed inside of the combobox (column names have something in common, and thats "Sezonalni_utjecaj_", but I have other columns too, not only ones that have "Sezonalni_utjecaj_" inside their name but I dont need their names ).

我的界面:

当我按Ok时,这是它背后的代码:

When i press "Ok" this is code behind it:

btnOk_2 = new JButton("Ok");
    btnOk_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {

            try {
                String kolumna=(String)textField.getText();
                String upit="alter table Linearni_trend_s_sezonalnim_utjecajem add column 'Sezonalni_utjecaj_"+kolumna+"' float;";
                PreparedStatement pst1 = konekcija.prepareStatement(upit);
                pst1.execute();
                pst1.close();
            } catch (SQLException e) {

                e.printStackTrace();
            }


推荐答案

实际上,Pragma可以帮助您获取类型等所有列名称等。 PRAGMA_SQL

Actually Pragma can help you to get all columns name with type etc etc.PRAGMA_SQL

  PRAGMA table_info(table_name);

或者您可以使用其他方式;

Alternatively you may use another way like ;

SELECT sql FROM sqlite_master
WHERE tbl_name = 'table_name' AND type = 'table'

这篇关于使用Java GUI从SQLite中的表返回列名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆