java代码:
java
String databaseUrl = "jdbc:sqlite:" + selectedFile.getPath();
ObservableList<ObservableList<Object>> masterData = FXCollections.observableArrayList();
try (Connection connection = DriverManager.getConnection(databaseUrl)) {
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM H_113_Sheet1");
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount(); // 获取列的数量
while (resultSet.next()) {
ObservableList<Object> row = FXCollections.observableArrayList();
for (int i = 1; i <= columnCount; i++) {
row.add(resultSet.getObject(i));
}
masterData.add(row);
}
} catch (SQLException e) {
e.printStackTrace();
}
c#代码:
cs
string databaseUrl = "Data Source=" + selectedFilePath;
List<List<object>> masterData = new List<List<object>>();
using (SQLiteConnection connection = new SQLiteConnection(databaseUrl))
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand("SELECT * FROM H_113_Sheet1", connection))
{
using (SQLiteDataReader reader = command.ExecuteReader())
{
DataTable schemaTable = reader.GetSchemaTable();
int columnCount = schemaTable.Columns.Count;
while (reader.Read())
{
List<object> row = new List<object>();
for (int i = 0; i < columnCount; i++)
{
row.Add(reader.GetValue(i));
}
masterData.Add(row);
}
}
}
}
catch (SQLiteException e)
{
Console.WriteLine(e.ToString());
}
结论:同样的一个sqlite数据库表,同样一台电脑,单机测试数据读取到内存。
java jdbc ,c# ado.net。
java jdbc:用时26秒,内存占用2.58G。
c# ado.net:用时34秒,内存占用1.68。
就是说取数这项,java内存占用是.net的1.5倍,速度比.net快30%多。