database - inserting double dimensional array into ms-access dynamically in java -


i want insert double dimensional array ms-access dynamically in java ..

here code..

    try {     class.forname("sun.jdbc.odbc.jdbcodbcdriver");     string url = "jdbc:odbc:driver={microsoft access driver " +         "(*.mdb, *.accdb)};dbq=c:\\documents , settings\\anil kumar\\desktop\\hyperdata.mdb";     con = drivermanager.getconnection(url);     system.out.println("connected!");     }     catch (sqlexception e) {         system.out.println("sql exception: "+ e.tostring());     }      catch (exception e) {        e.printstacktrace();      } 

if have string array 2 columns:

string[][] = new string[10][2]; preparedstatement pst = con.preparestatement("insert sap_details values (?,?)"); (int = 0; < 10; i++) {     pst.setstring(1, a[i][0]);     pst.setstring(2, a[i][1]);     pst.addbatch(); } pst.executebatch(); 

what if have have string array n columns , n rows? how insert string array a[n][n]?

have inner loop

for (int i=0; i<a.length; i++) {   (int j=0; j<a[i].length; j++) {      system.out.print(a[i][j]);   } } 

you can use enhanced loop below

for (string[] array : a) {     (string s : array) {       system.out.println(s);      }   } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -