H2怎麼樣? License應該適合你。
- 您可以免費使用H2。您可以將 集成到您的應用程序 (包括商業應用程序), ,您可以分發它。
- 文件 只包含你的代碼是不是 該許可證所覆蓋(這是 「商業友好」)。
- 修改爲 的H2源代碼必須爲 發佈。
- 如果你沒有 修改任何東西,你不需要提供H2的源代碼 。
我得到了22492ms(44460.252534234394行/秒)
100000更新在9565ms(10454.783063251438行/秒)
從
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Random;
/**
* @author clint
*
*/
public class H2Test {
static int testrounds = 1000000;
public static void main(String[] args) {
try {
Class.forName("org.h2.Driver");
Connection conn = DriverManager.
getConnection("jdbc:h2:/tmp/test.h2", "sa", "");
// add application code here
conn.createStatement().execute("DROP TABLE IF EXISTS TEST");
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS TEST(id INT PRIMARY KEY, browser VARCHAR(64),ip varchar(16), outcome real)");
//conn.createStatement().execute("CREATE INDEX IDXall ON TEST(id,browser,ip,outcome");
PreparedStatement ps = conn.prepareStatement("insert into TEST (id, browser, ip, outcome) values (?,?,?,?)");
long time = System.currentTimeMillis();
for (int i = 0; i < testrounds; i++) {
ps.setInt(1,i);
ps.setString(2,"firefox");
ps.setString(3,"000.000.000.000");
ps.setFloat(4,0);
ps.execute();
}
long last = System.currentTimeMillis() ;
System.out.println(testrounds + " insert in " + (last - time) + "ms (" + ((testrounds)/((last - time)/1000d)) + " row/sec)");
ps.close();
ps = conn.prepareStatement("update TEST set outcome = 1 where id=?");
Random random = new Random();
time = System.currentTimeMillis();
/// randomly updadte 10% of the entries
for (int i = 0; i < testrounds/10; i++) {
ps.setInt(1,random.nextInt(testrounds));
ps.execute();
}
last = System.currentTimeMillis();
System.out.println((testrounds/10) + " updates in " + (last - time) + "ms (" + ((testrounds/10)/((last - time)/1000d)) + " row/sec)");
conn.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
百萬插入
「DB4O不是一個選項,因爲它是GPL,我的其他代碼不是」 - 只有在您計劃分發代碼時才重要。 – 2009-08-14 03:13:25
我打算分發我的代碼 – sanity 2009-08-14 03:42:18