Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
creating table with jackcess
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import com.healthmarketscience.jackcess.ColumnBuilder;
import com.healthmarketscience.jackcess.DataType;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.Table;
import com.healthmarketscience.jackcess.TableBuilder;
public class CreateTable {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String db_name = "/home/xxxx/Dropbox/doc/mdb/jack.mdb";
String table_name = "sample_table0";
File file = new File(db_name);
Database db=null;
try {
db = DatabaseBuilder.open(file);
Collection<ColumnBuilder> columnbuilders = new ArrayList<ColumnBuilder>();
// columnbuilders.setL;
columnbuilders.add(new ColumnBuilder("col1",DataType.TEXT).setLength(100));
columnbuilders.add(new ColumnBuilder("col2",DataType.TEXT).setLength(510));
columnbuilders.add(new ColumnBuilder("col3",DataType.BOOLEAN));
columnbuilders.add(new ColumnBuilder("col4",DataType.BYTE));
columnbuilders.add(new ColumnBuilder("col5",DataType.DOUBLE));
columnbuilders.add(new ColumnBuilder("col6",DataType.LONG));
columnbuilders.add(new ColumnBuilder("col7",DataType.LONG).setAutoNumber(true));
columnbuilders.add(new ColumnBuilder("col8",DataType.MEMO));
columnbuilders.add(new ColumnBuilder("col9",DataType.MONEY));
columnbuilders.add(new ColumnBuilder("col10",DataType.SHORT_DATE_TIME));
columnbuilders.add(new ColumnBuilder("col11",DataType.NUMERIC));
columnbuilders.add(new ColumnBuilder("col12",DataType.BINARY));
Table table0 = new TableBuilder(table_name)
.addColumns(columnbuilders)
.toTable(db);
db.close();
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
System.out.println(e.getMessage());
}catch(Exception ee){
System.out.println(ee.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment