• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.healthmarketscience.jackcess.Database的典型用法代码示例。如果您正苦于以下问题:Java Database类的具体用法?Java Database怎么用?Java Database使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Database类属于com.healthmarketscience.jackcess包,在下文中一共展示了Database类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createUniqueTable

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
/**
 * Returns a new table with a unique name and the given table definition.
 */
private static Table createUniqueTable(Database db, String name,
                                       List<ColumnBuilder> columns,
                                       ResultSetMetaData md, 
                                       ImportFilter filter)
  throws IOException, SQLException
{
  // otherwise, find unique name and create new table
  String baseName = name;
  int counter = 2;
  while(db.getTable(name) != null) {
    name = baseName + (counter++);
  }
  
  return new TableBuilder(name)
    .addColumns(filter.filterColumns(columns, md))
    .toTable(db);
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:21,代码来源:ImportUtil.java


示例2: testImportFromFileWithOnlyHeaders

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testImportFromFileWithOnlyHeaders() throws Exception
{
  for (final FileFormat fileFormat : JetFormatTest.SUPPORTED_FILEFORMATS) {
    Database db = create(fileFormat);
    String tableName = new ImportUtil.Builder(db, "test")
      .setDelimiter("\\t")
      .importFile(new File("src/test/data/sample-input-only-headers.tab"));

    Table t = db.getTable(tableName);

    List<String> colNames = new ArrayList<String>();
    for(Column c : t.getColumns()) {
      colNames.add(c.getName());
    }
    assertEquals(Arrays.asList(
                     "RESULT_PHYS_ID", "FIRST", "MIDDLE", "LAST", "OUTLIER",
                     "RANK", "CLAIM_COUNT", "PROCEDURE_COUNT",
                     "WEIGHTED_CLAIM_COUNT", "WEIGHTED_PROCEDURE_COUNT"), 
                 colNames);

    db.close();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:ImportTest.java


示例3: toFile

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public static final JackcessDenseObjectMatrix2D toFile(File file, Object... parameters)
		throws IOException {
	Database db = DatabaseBuilder.open(file);
	Set<String> tables = db.getTableNames();
	String tablename = null;

	if (parameters.length != 0) {
		tablename = StringUtil.convert(parameters[0]);
	}
	if (tablename == null) {
		if (tables.size() == 1) {
			tablename = db.getTableNames().iterator().next();
		}
	}

	db.close();

	if (tablename == null) {
		throw new IllegalArgumentException(
				"please append the table name, i.e. one of these tables: " + tables);
	}

	return new JackcessDenseObjectMatrix2D(file, tablename);
}
 
开发者ID:ujmp,项目名称:universal-java-matrix-package,代码行数:25,代码来源:LinkMatrixMDB.java


示例4: getTable

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
private TableImpl getTable(TableInfo tableInfo, boolean includeSystemTables) 
  throws IOException 
{
  if(tableInfo.isLinked()) {

    if(_linkedDbs == null) {
      _linkedDbs = new HashMap<String,Database>();
    }

    String linkedDbName = ((LinkedTableInfo)tableInfo).linkedDbName;
    String linkedTableName = ((LinkedTableInfo)tableInfo).linkedTableName;
    Database linkedDb = _linkedDbs.get(linkedDbName);
    if(linkedDb == null) {
      linkedDb = getLinkResolver().resolveLinkedDatabase(this, linkedDbName);
      _linkedDbs.put(linkedDbName, linkedDb);
    }
    
    return ((DatabaseImpl)linkedDb).getTable(linkedTableName, 
                                             includeSystemTables);
  }

  return readTable(tableInfo.tableName, tableInfo.pageNumber,
                   tableInfo.flags);
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:25,代码来源:DatabaseImpl.java


示例5: testReadCalcFields

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testReadCalcFields() throws Exception {

    for(TestDB testDB : TestDB.getSupportedForBasename(Basename.CALC_FIELD)) {
      Database db = open(testDB);
      Table t = db.getTable("Table1");

      List<String> rows = new ArrayList<String>();
      for(Row r : t) {
        rows.add(r.entrySet().toString());
      }

      List<String> expectedRows = Arrays.asList(
          "[ID=1, FirstName=Bruce, LastName=Wayne, LastFirst=Wayne, Bruce, City=Gotham, LastFirstLen=12, Salary=1000000.0000, MonthlySalary=83333.3333, IsRich=true, AllNames=Wayne, Bruce=Wayne, Bruce, WeeklySalary=19230.7692307692, SalaryTest=1000000.0000, BoolTest=true, Popularity=50.325000, DecimalTest=50.325000, FloatTest=2583.2092, BigNumTest=56505085819.424791296572280180]",
          "[ID=2, FirstName=Bart, LastName=Simpson, LastFirst=Simpson, Bart, City=Springfield, LastFirstLen=13, Salary=-1.0000, MonthlySalary=-0.0833, IsRich=false, AllNames=Simpson, Bart=Simpson, Bart, WeeklySalary=-0.0192307692307692, SalaryTest=-1.0000, BoolTest=true, Popularity=-36.222200, DecimalTest=-36.222200, FloatTest=0.0035889593, BigNumTest=-0.0784734499180612994241100748]",
          "[ID=3, FirstName=John, LastName=Doe, LastFirst=Doe, John, City=Nowhere, LastFirstLen=9, Salary=0.0000, MonthlySalary=0.0000, IsRich=false, AllNames=Doe, John=Doe, John, WeeklySalary=0, SalaryTest=0.0000, BoolTest=true, Popularity=0.012300, DecimalTest=0.012300, FloatTest=0.0, BigNumTest=0E-8]",
          "[ID=4, FirstName=Test, LastName=User, LastFirst=User, Test, City=Hockessin, LastFirstLen=10, Salary=100.0000, MonthlySalary=8.3333, IsRich=false, AllNames=User, Test=User, Test, WeeklySalary=1.92307692307692, SalaryTest=100.0000, BoolTest=true, Popularity=102030405060.654321, DecimalTest=102030405060.654321, FloatTest=1.27413E-10, BigNumTest=2.787019289824216980830E-7]");

      assertEquals(expectedRows, rows);

      db.close();
    }    
  }
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:23,代码来源:CalcFieldTest.java


示例6: x_testCreateIsoFile

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void x_testCreateIsoFile() throws Exception
{
  Database db = create(Database.FileFormat.V2000, true);

  Table t = new TableBuilder("test")
    .addColumn(new ColumnBuilder("row", DataType.TEXT))
    .addColumn(new ColumnBuilder("data", DataType.TEXT))
    .toTable(db);
  
  for(int i = 0; i < 256; ++i) {
    String str = "AA" + ((char)i) + "AA";
    t.addRow("row" + i, str);
  }

  db.close();
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:IndexCodesTest.java


示例7: x_testReadAllCodesMdb

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void x_testReadAllCodesMdb() throws Exception
  {
//     Database db = openCopy(new File("/data2/jackcess_test/testAllIndexCodes.mdb"));
//     Database db = openCopy(new File("/data2/jackcess_test/testAllIndexCodes_orig.mdb"));
//     Database db = openCopy(new File("/data2/jackcess_test/testSomeMoreCodes.mdb"));
    Database db = openCopy(Database.FileFormat.V2000, new File("/data2/jackcess_test/testStillMoreCodes.mdb"));
    Table t = db.getTable("Table5");

    Index ind = t.getIndexes().iterator().next();
    ((IndexImpl)ind).initialize();
    
    System.out.println("Ind " + ind);

    Cursor cursor = CursorBuilder.createCursor(ind);
    while(cursor.moveToNextRow()) {
      System.out.println("=======");
      String entryStr = 
        entryToString(cursor.getSavepoint().getCurrentPosition());
      System.out.println("Entry Bytes: " + entryStr);
      System.out.println("Value: " + cursor.getCurrentRow() + "; " +
                         toUnicodeStr(cursor.getCurrentRow().get("data")));
    }

    db.close();
  }
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:26,代码来源:IndexCodesTest.java


示例8: x_testReadIsoMdb

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void x_testReadIsoMdb() throws Exception
  {
//     Database db = open(new File("/tmp/test_ind.mdb"));
//     Database db = open(new File("/tmp/test_ind2.mdb"));
    Database db = open(Database.FileFormat.V2000, new File("/tmp/test_ind3.mdb"));
//     Database db = open(new File("/tmp/test_ind4.mdb"));

    Table t = db.getTable("Table1");
    Index index = t.getIndex("B");
    ((IndexImpl)index).initialize();
    System.out.println("Ind " + index);

    Cursor cursor = CursorBuilder.createCursor(index);
    while(cursor.moveToNextRow()) {
      System.out.println("=======");
      System.out.println("Savepoint: " + cursor.getSavepoint());
      System.out.println("Value: " + cursor.getCurrentRow());
    }
    
    db.close();
  }
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:22,代码来源:IndexCodesTest.java


示例9: testRead

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testRead() throws Exception {
  for (final TestDB testDB : SUPPORTED_DBS_TEST) {
    final int expectedFirstPage;
    final int expectedLastPage;
    final Database.FileFormat expectedFileFormat = testDB.getExpectedFileFormat();
    if (Database.FileFormat.V2000.equals(expectedFileFormat)) {
      expectedFirstPage = 743;
      expectedLastPage = 767;
    } else if (Database.FileFormat.V2003.equals(expectedFileFormat)) {
      expectedFirstPage = 16;
      expectedLastPage = 799;
    } else if (Database.FileFormat.V2007.equals(expectedFileFormat)) {
      expectedFirstPage = 94;
      expectedLastPage = 511;
    } else if (Database.FileFormat.V2010.equals(expectedFileFormat)) {
      expectedFirstPage = 109;
      expectedLastPage = 511;
    } else {
      throw new IllegalAccessException("Unknown file format: " + expectedFileFormat);
    }
    checkUsageMapRead(testDB.getFile(), expectedFirstPage, expectedLastPage);
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:UsageMapTest.java


示例10: testReadLongValue

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testReadLongValue() throws Exception {

    for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.TEST2, true)) {
      Database db = openMem(testDB);
      Table table = db.getTable("MSP_PROJECTS");
      Row row = table.getNextRow();
      assertEquals("Jon Iles this is a a vawesrasoih aksdkl fas dlkjflkasjd flkjaslkdjflkajlksj dfl lkasjdf lkjaskldfj lkas dlk lkjsjdfkl; aslkdf lkasjkldjf lka skldf lka sdkjfl;kasjd falksjdfljaslkdjf laskjdfk jalskjd flkj aslkdjflkjkjasljdflkjas jf;lkasjd fjkas dasdf asd fasdf asdf asdmhf lksaiyudfoi jasodfj902384jsdf9 aw90se fisajldkfj lkasj dlkfslkd jflksjadf as", row.get("PROJ_PROP_AUTHOR"));
      assertEquals("T", row.get("PROJ_PROP_COMPANY"));
      assertEquals("Standard", row.get("PROJ_INFO_CAL_NAME"));
      assertEquals("Project1", row.get("PROJ_PROP_TITLE"));
      byte[] foundBinaryData = row.getBytes("RESERVED_BINARY_DATA");
      byte[] expectedBinaryData =
        toByteArray(new File("src/test/data/test2BinData.dat"));
      assertTrue(Arrays.equals(expectedBinaryData, foundBinaryData));

      db.close();
    }
  }
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:19,代码来源:LongValueTest.java


示例11: testLongValueAsMiddleColumn

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testLongValueAsMiddleColumn() throws Exception
{
  for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
    Database db = createMem(fileFormat);
    Table newTable = new TableBuilder("NewTable")
      .addColumn(new ColumnBuilder("a").setSQLType(Types.INTEGER))
      .addColumn(new ColumnBuilder("b").setSQLType(Types.LONGVARCHAR))
      .addColumn(new ColumnBuilder("c").setSQLType(Types.VARCHAR))
      .toTable(db);

    String lval = createString(2000); // "--2000 chars long text--";
    String tval = createString(40); // "--40chars long text--";
    newTable.addRow(new Integer(1), lval, tval);

    newTable = db.getTable("NewTable");
    Map<String, Object> readRow = newTable.getNextRow();
    assertEquals(new Integer(1), readRow.get("a"));
    assertEquals(lval, readRow.get("b"));
    assertEquals(tval, readRow.get("c"));

    db.close();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:LongValueTest.java


示例12: doTestWriteAndRead

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
private static void doTestWriteAndRead(Database db) throws Exception {
    createTestTable(db);
    Object[] row = createTestRow();
    row[3] = null;
    Table table = db.getTable("Test");
    int count = 1000;
    ((DatabaseImpl)db).getPageChannel().startWrite();
    try {
      for (int i = 0; i < count; i++) {
        table.addRow(row);
      }
    } finally {
      ((DatabaseImpl)db).getPageChannel().finishWrite();
    }
    for (int i = 0; i < count; i++) {
      Map<String, Object> readRow = table.getNextRow();
      assertEquals(row[0], readRow.get("A"));
      assertEquals(row[1], readRow.get("B"));
      assertEquals(row[2], readRow.get("C"));
      assertEquals(row[3], readRow.get("D"));
      assertEquals(row[4], readRow.get("E"));
      assertEquals(row[5], readRow.get("F"));
      assertEquals(row[6], readRow.get("G"));
      assertEquals(row[7], readRow.get("H"));
    }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:27,代码来源:DatabaseReadWriteTest.java


示例13: testAutoNumber

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testAutoNumber() throws Exception 
{
  for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
    Database db = createMem(fileFormat);

    Table table = new TableBuilder("test")
      .addColumn(new ColumnBuilder("a", DataType.LONG)
                .setAutoNumber(true))
      .addColumn(new ColumnBuilder("b", DataType.TEXT))
      .toTable(db);

    doTestAutoNumber(table);

    db.close();
  }
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:AutoNumberTest.java


示例14: testInsertLongAutoNumber

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testInsertLongAutoNumber() throws Exception
{
  for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
    Database db = createMem(fileFormat);

    Table table = new TableBuilder("test")
      .addColumn(new ColumnBuilder("a", DataType.LONG)
                .setAutoNumber(true))
      .addColumn(new ColumnBuilder("b", DataType.TEXT))
      .toTable(db);

    doTestInsertLongAutoNumber(table);

    db.close();
  }    
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:17,代码来源:AutoNumberTest.java


示例15: testInsertLongAutoNumberPK

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testInsertLongAutoNumberPK() throws Exception
{
  for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
    Database db = createMem(fileFormat);

    Table table = new TableBuilder("test")
      .addColumn(new ColumnBuilder("a", DataType.LONG)
                .setAutoNumber(true))
      .addColumn(new ColumnBuilder("b", DataType.TEXT))
      .setPrimaryKey("a")
      .toTable(db);

    doTestInsertLongAutoNumber(table);

    db.close();
  }    
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:18,代码来源:AutoNumberTest.java


示例16: testNoEnforceForeignKeys

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testNoEnforceForeignKeys() throws Exception {
  for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX)) {

    Database db = openCopy(testDB);
    db.setEnforceForeignKeys(false);
    Table t1 = db.getTable("Table1");
    Table t2 = db.getTable("Table2");
    Table t3 = db.getTable("Table3");

    t1.addRow(20, 0, 20, "some data", 20);

    Cursor c = CursorBuilder.createCursor(t2);
    c.moveToNextRow();
    c.updateCurrentRow(30, "foo30");

    c = CursorBuilder.createCursor(t3);
    c.moveToNextRow();
    c.deleteCurrentRow();

    db.close();
  }
  
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:FKEnforcerTest.java


示例17: testSqlTypes

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
public void testSqlTypes() throws Exception {
  
  JetFormat v2000 = JetFormat.VERSION_4;
  for(DataType dt : DataType.values()) {
    if(v2000.isSupportedDataType(dt)) {
      Integer sqlType = null;
      try {
        sqlType = dt.getSQLType();
      } catch(SQLException ignored) {}

      if(sqlType != null) {
        assertEquals(dt, DataType.fromSQLType(sqlType));
      }
    }
  }

  assertEquals(DataType.LONG, DataType.fromSQLType(java.sql.Types.BIGINT));
  assertEquals(DataType.BIG_INT, DataType.fromSQLType(
                   java.sql.Types.BIGINT, 0, Database.FileFormat.V2016));
  assertEquals(java.sql.Types.BIGINT, DataType.BIG_INT.getSQLType());
  assertEquals(DataType.MEMO, DataType.fromSQLType(
                   java.sql.Types.VARCHAR, 1000));
}
 
开发者ID:jahlborn,项目名称:jackcess,代码行数:24,代码来源:JetFormatTest.java


示例18: export

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
/**
 * Export the Access database to the given SQLite database. The referenced
 * SQLite database should be empty.
 * 
 * @param mdbFile The MS Access file.
 * @param sqliteFile The SQLite file.
 * @throws SQLException
 * @throws SqlJetException
 */
public static void export(File mdbFile, File sqliteFile) throws Exception {
	Database mdb = DatabaseBuilder.open(mdbFile);

	SqlJetDb sqlite = SqlJetDb.open(sqliteFile, true);
	sqlite.getOptions().setAutovacuum(true);
	sqlite.beginTransaction(SqlJetTransactionMode.WRITE);

	// Create the tables
	MDB2SQLite.createTables(mdb, sqlite);

	// Populate the tables
	for (String tableName : mdb.getTableNames()) {
		MDB2SQLite.populateTable(sqlite, mdb.getTable(tableName));
	}
}
 
开发者ID:mbrigl,项目名称:mdb2sqlite,代码行数:25,代码来源:MDB2SQLite.java


示例19: createTables

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
/**
 * Iterate over the MDB database and create SQLite tables for every table
 * defined in the MS Access database.
 * 
 * @param jdbc The SQLite database JDBC connection
 */
@SuppressWarnings("unchecked")
private static void createTables(Database mdb, SqlJetDb sqlite) throws Exception {
	for (String tableName : mdb.getTableNames()) {
		Table table = mdb.getTable(tableName);
		sqlite.beginTransaction(SqlJetTransactionMode.WRITE);
		try {
			sqlite.createTable(MDB2SQLite.createTableStatement(table));
			for (Index index : (List<Index>) table.getIndexes()) {
				sqlite.createIndex(MDB2SQLite.createIndexStatement(index));
			}
		} finally {
			sqlite.commit();
		}
	}
}
 
开发者ID:mbrigl,项目名称:mdb2sqlite,代码行数:22,代码来源:MDB2SQLite.java


示例20: enlistCreateTable

import com.healthmarketscience.jackcess.Database; //导入依赖的package包/类
private void enlistCreateTable(String sql, DDLType ddlType)
		throws SQLException {
	String tn = ddlType.getDBObjectName(sql);
	UcanaccessConnection ac = UcanaccessConnection.getCtxConnection();
	String execId = UcanaccessConnection.getCtxExcId();
	Connection hsqlConn = ac.getHSQLDBConnection();
	Database db = ac.getDbIO();
	LoadJet lfa = new LoadJet(hsqlConn, db);
	lfa.synchronisationTriggers(tn, true,true);
	CreateTableCommand c4io;
      if(ddlType.equals(DDLType.CREATE_TABLE)){
   	   parseTypesFromCreateStatement(sql);
   	   c4io=new CreateTableCommand(
			tn, execId, this.types,this.defaults,this.notNulls);
   	   }
      else  {
   	   c4io=new CreateTableCommand(tn, execId);
      }
     
	ac.add(c4io); 
}
 
开发者ID:andrew-nguyen,项目名称:ucanaccess,代码行数:22,代码来源:DDLCommandEnlist.java



注:本文中的com.healthmarketscience.jackcess.Database类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UpdateType类代码示例发布时间:2022-05-21
下一篇:
Java AuthenticationToken类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap