java - Print database column and data -


i connection db , data , column.

i want print them:

public class jdbc1 {  static vector<string> columns = new vector<string>(); vector<vector<string>> data = new vector<vector<string>>(); connection con; statement statement; resultset result;  public vector<string> getcolumns() throws sqlexception {      con = drivermanager.getconnection(...);     statement = con.createstatement();     result = statement.executequery("select * table");      int c = result.getmetadata().getcolumncount();     (int = 1; <= c; i++) {         columns.add(result.getmetadata().getcolumnname(i));     }     return columns; }  public vector<vector<string>> getdata() throws sqlexception {     con = drivermanager.getconnection(...);     statement = con.createstatement();     result = statement.executequery("select * table");     int c = result.getmetadata().getcolumncount();      while (result.next()) {         vector<string> newrow = new vector<string>(c);          (int = 1; <= c; i++) {             newrow.add(result.getstring(i));         }         data.add(newrow);     }     return data;  }  public static void main(string[] args) {     system.out.println(string.valueof(getcolumns()));  // error     system.out.println(string.valueof(getgetdata()));  // error } } 

how println vectors? ....................................................................................................................

you have extract each element out of vector using get() method appropriate index, follows:

string str = vector.get(i); system.out.print(str); 

or iterate through vector for-loop:

for (string str : vector) {     system.out.println(str); } 

in case, you'll want iterate this:

for (string str : getcolumns()) {     system.out.println(str); } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -