Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Vector getTableData() throws SQLException, ClassNotFoundException{
- //connect to database
- Vector data = new Vector();
- Class.forName("org.sqlite.JDBC");
- Connection conn = DriverManager.getConnection("jdbc:sqlite:prova.db");
- Statement stmt = conn.createStatement();
- //read data from db
- // Read data from a table
- String sql = "SELECT * FROM people";
- ResultSet rs = stmt.executeQuery( sql );
- ResultSetMetaData md = rs.getMetaData();
- int columns = md.getColumnCount();
- // Get column names
- // Get row data
- while (rs.next())
- {
- Vector row = new Vector(columns);
- for (int i = 1; i <= columns; i++)
- {
- row.addElement(rs.getObject(i));
- }
- data.addElement(row);
- }
- rs.close();
- stmt.close();
- return data;
- }
- public static Vector getColumnNames() throws SQLException, ClassNotFoundException{
- //connect to database
- Vector columnNames = new Vector();
- Class.forName("org.sqlite.JDBC");
- Connection conn = DriverManager.getConnection("jdbc:sqlite:prova.db");
- Statement stmt = conn.createStatement();
- //read data from db
- // Read data from a table
- String sql = "SELECT * FROM people";
- ResultSet rs = stmt.executeQuery( sql );
- ResultSetMetaData md = rs.getMetaData();
- int columns = md.getColumnCount();
- // Get column names
- for (int i = 1; i <= columns; i++)
- {
- columnNames.addElement( md.getColumnName(i) );
- }
- return columnNames;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement