当前位置: 首页>>代码示例>>Java>>正文


Java Database类代码示例

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


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


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