package jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
public class TestSqlite {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
String driver = "org.sqlite.JDBC";
String db = "C:\\Qt\\ws\\StudentSys\\stu.db";
String url = "jdbc:sqlite:" + db;
String sql = "select * from tb_student";
Class.forName(driver);
Connection cn = DriverManager.getConnection(url);
Statement stat = cn.createStatement();
ResultSet rs = stat.executeQuery(sql);
ResultSetMetaData md = rs.getMetaData();
int cols = rs.getMetaData().getColumnCount();
for(int i=1; i<=cols; i++) {
System.out.print(md.getColumnName(i)+"\t");
}
while(rs.next()) {
System.out.println();
for(int i=1; i<=cols; i++) {
System.out.print(rs.getString(i)+"\t\t");
}
}
}
}