标签:显示 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 // 显示应用 GUI 19 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驱动下载
标签:显示 color awt getc rom data sqli als 功能
原文地址:http://www.cnblogs.com/zdfbk/p/7447029.html