Java Swing Interface Query database table

Source: Internet
Author: User

Written in two days. There is no button dialog box function, just a simple implementation.

Of course the code has a lot to optimize, the basic need to rewrite hahaha. But I'm afraid I need it later, so I'd better save it. "Put RS result set, put vector inside, construct jtable with vector"

1  Packagemetersqllitedatafinal;2 3 Importjava.awt.Dimension;4 ImportJava.util.Vector;5 ImportJavax.swing.JButton;6 ImportJavax.swing.JFrame;7 ImportJavax.swing.JLabel;8 ImportJavax.swing.JScrollPane;9 Importjavax.swing.JTable;Ten  One  Public classMainnextendsJFrame { A     //private Vector RowData, ColumnName; -     PrivateJTable JT =NULL; -     PrivateJScrollPane jsp =NULL; the     PrivateJButton JB =NULL; -  -      Public Static voidMain (string[] args) { -         //Display Application GUI +Mainn miann1 =NewMainn (); -     } +      A      PublicMainn () at     { -Sqlitedata A =NewSqlitedata (); -          //Initialize JTable - a.mainjj (); -                   -JT =NewJTable (A.rowdata, a.columnname);  in            -JSP =NewJScrollPane (JT);  to          +          This. Add (JSP);  -          This. Settitle ("By:zing Zhuang sqlliteconnect");  the          This. SetSize (460, 200);//This is the size *          This. setlocation (300, 200);//This is the location . $          This. Setdefaultcloseoperation (Jframe.exit_on_close); Panax Notoginseng          This. setresizable (true);//size is variable -          This. setvisible (true);//Show and Hide the     } +      A}
 Packagemetersqllitedatafinal;Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;ImportJava.sql.ResultSetMetaData;Importjava.sql.Statement;ImportJava.util.Vector;ImportJavax.swing.JScrollPane;Importjavax.swing.JTable;ImportOrg.omg.CORBA.PRIVATE_MEMBER; Public classSqlitedata { PublicVector RowData, ColumnName; PrivateJTable JT =NULL; PrivateJScrollPane jsp =NULL; intKK = 2;  Public voidMainjj () {Connection C=NULL; Statement stmt=NULL; String Kongge=NewString ("\ t"); String Huiche=NewString ("\ n"); String Shuchu= ""; RowData=NewVector (); Try{class.forname ("Org.sqlite.JDBC"); C= Drivermanager.getconnection ("jdbc:sqlite:d:\\easyenergydata\\easyenergy.data\\");//Tim.data EasyenergyC.setautocommit (false); System.out.println ("Opened database successfully"); stmt=c.createstatement (); ResultSet RS= Stmt.executequery ("select * from Meter;");// CompanyResultSetMetaData data =Rs.getmetadata (); ColumnName=NewVector (); System.out.println ("DD");  for(inti = 1; I <= data.getcolumncount (); i++) {Shuchu=Data.getcolumnname (i);            Columnname.add (Shuchu); }                         while(Rs.next ()) {Vector line1=NewVector ();  for(intK = 1; K <= Data.getcolumncount (); k++) {Shuchu=rs.getstring (Data.getcolumnname (k));                        Line1.add (Shuchu); System.out.println ("There is no error in the loop" +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"); }}

Drivers that need to be imported

The project needs to import the SQL driver. Build path→configure build Path→add External JARs

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

This is a reference to the place.

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

This reference how to transfer data into

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

This has not been used for reference, but very detailed.

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

Here is the sqllite driver download

Java Swing Interface Query database table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.