时间:2021-07-01 10:21:17 帮助过:17人阅读
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 界面化查询数据库表
标签:显示 color awt getc rom data sqli als 功能