代码,
import java.awt.Container;
import java.awt.Color;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class lnxcmd {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
JFrame frame=new JFrame("Linux命令查询");
frame.setSize(800,600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane=frame.getContentPane();
Class.forName("org.sqlite.JDBC");
String db = "F:\\JavaWorkSpace\\swing\\lnxcmd.db";
Connection conn = DriverManager.getConnection("jdbc:sqlite:" + db);
Statement state = conn.createStatement();
ResultSet rs = state.executeQuery("select * from lnxcmd;");
DefaultTableModel model = new DefaultTableModel();
model.addColumn("命令");
model.addColumn("功能");
model.addColumn("参数");
model.addColumn("示例");
Object[] rowData = null;
while (rs.next()) {
rowData = new Object[4];
rowData[0] = rs.getString("lnxcmd");
rowData[1] = rs.getString("funcs");
rowData[2] = rs.getString("params");
rowData[3] = rs.getString("exams");
model.addRow(rowData);
}
JTable table=new JTable(model);
JScrollPane scroll = new JScrollPane(table);
//scroll.getViewport().setBackground(Color.GREEN);
contentPane.add(scroll);
JButton b1=new JButton("查询");
JButton b2=new JButton("修改");
JButton b3=new JButton("删除");
JButton b4=new JButton("清空");
JButton b5=new JButton("添加");
//contentPane.add(b1);
//contentPane.add(b2);
//contentPane.add(b3);
//contentPane.add(b4);
//contentPane.add(b5);
frame.setVisible(true);
rs.close();
conn.close();
}
}
数据库只有一条记录;
sqlite-jdbc-x.x.x.jar 在同一目录下;