当前位置: 动力学知识库 > 问答 > 编程问答 >

sql - Returning column names from table in SQLite using Java GUI

问题描述:

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

My Interface

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

}

网友答案:

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'
分享给朋友:
您可能感兴趣的文章:
随机阅读: