java Swing 介面化查詢資料庫表

來源:互聯網
上載者:User

標籤:顯示   color   awt   getc   rom   data   sqli   als   功能   

兩天寫的。沒有按鈕對話方塊功能,只是簡單的實現。

當然代碼上有很多需要最佳化的,基本需要重寫哈哈哈。但是我怕以後有需要所以還是存一下好了。《把RS結果集,放vector裡面,用vector構造JTable》

 1 package meterSqllitedataFinal; 2  3 import java.awt.Dimension; 4 import java.util.Vector; 5 import javax.swing.JButton; 6 import javax.swing.JFrame; 7 import javax.swing.JLabel; 8 import javax.swing.JScrollPane; 9 import javax.swing.JTable;10 11 public class mainn extends JFrame {12     //private Vector rowData, columnName;13     private JTable jt = null;14     private JScrollPane jsp = null;15     private JButton jb = null;16 17     public static void main(String[] args) {18         // 顯示應用 GUI19         mainn miann1 = new mainn();20     }21     22     public mainn()23     {24         sqlitedata a = new sqlitedata();25          //初始化JTable  26         a.mainjj();27                  28         jt = new JTable(a.rowData, a.columnName);  29           30         jsp = new JScrollPane(jt);  31         32         this.add(jsp);  33         this.setTitle("by:Zing莊     SqlliteConnect");  34         this.setSize(460, 200);  //這是大小35         this.setLocation(300, 200);  //這是位置36         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  37         this.setResizable(true);  //尺寸是否可變38         this.setVisible(true);  //顯示與隱藏39     }40     41 }
package meterSqllitedataFinal;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.ResultSetMetaData;import java.sql.Statement;import java.util.Vector;import javax.swing.JScrollPane;import javax.swing.JTable;import org.omg.CORBA.PRIVATE_MEMBER;public class sqlitedata {    public  Vector rowData, columnName;      private JTable jt = null;    private JScrollPane jsp = null;    int kk = 2;        public void mainjj() {        Connection c = null;        Statement stmt = null;        String kongge = new String("\t");        String huiche = new String("\n");        String shuchu = "";        rowData = new Vector();        try {            Class.forName("org.sqlite.JDBC");            c = DriverManager.getConnection("jdbc:sqlite:d:\\EasyEnergyData\\EasyEnergy.data\\");//tim.data  EasyEnergy            c.setAutoCommit(false);            System.out.println("Opened database successfully");            stmt = c.createStatement();            ResultSet rs = stmt.executeQuery("SELECT * FROM Meter;");//COMPANY            ResultSetMetaData data = rs.getMetaData();                        columnName = new Vector();              System.out.println("dd");                                                for (int i = 1; i <= data.getColumnCount(); i++) {                shuchu = data.getColumnName(i);                columnName.add(shuchu);            }                        while (rs.next()) {                    Vector line1 = new Vector();                    for (int k = 1; k <= data.getColumnCount(); k++) {                                                shuchu = rs.getString(data.getColumnName(k));                        line1.add(shuchu);                        System.out.println("這裡在迴圈沒有錯"+line1);                    }                    rowData.add(line1);                }                                rs.close();            stmt.close();            c.close();        } catch (Exception e) {            System.err.println(e.getClass().getName() + ": " + e.getMessage());            System.exit(0);        }        System.out.println("Operation done successfully");            }}

需要匯入的驅動

 

 

 

 

 

 

項目需要匯入sql驅動。build Path →Configure Build Path →Add External JARs

http://blog.csdn.net/qq_21478795/article/details/51579181

這個是借鑒的地方。

https://zhidao.baidu.com/question/2202449700556627748.html

這個借鑒如何傳輸進資料

http://blog.csdn.net/a412588063/article/details/21242887

這沒借鑒過,但是挺詳細的。

http://www.runoob.com/sqlite/sqlite-java.html

這裡是sqllite驅動下載

 

java Swing 介面化查詢資料庫表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.