Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mango 批量插入问题 #23

Closed
zhangzpap opened this issue Feb 13, 2017 · 1 comment
Closed

mango 批量插入问题 #23

zhangzpap opened this issue Feb 13, 2017 · 1 comment

Comments

@zhangzpap
Copy link

zhangzpap commented Feb 13, 2017

`public static void main(String[] args) {
long s = System.currentTimeMillis();
String driverClassName = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/mango_example";
String username = "root"; // 这里请使用您自己的用户名
String password = "123456"; // 这里请使用您自己的密码
DataSource ds = new DriverManagerDataSource(driverClassName, url, username, password);
Mango mango = Mango.newInstance(ds); // 使用数据源初始化mango
FruitDao dao = mango.create(FruitDao.class);
List list = new ArrayList<>();
for (int i = 0; i < 2000; i++) {
list.add(new Fruit("xxx" + i, i));
}
dao.add(list);

	System.out.println(":" + (System.currentTimeMillis() - s)); //:1m29s
}`

@DB interface FruitDao { @SQL("insert into fruit(name, num) values(:name, :num)") public int add(List<Fruit> list); }

根据官网的例子,批量插入需要1分29秒, 批量插入2000条。如果加上事物就是2秒,这是为啥?

Transaction tx = TransactionFactory.newTransaction(); dao.add(list); tx.commit();

@liangyanghe
Copy link
Member

hi,我在本机尝试了上面的代码,批量插入2000条,不使用事务,只话费了1秒多时间

操作系统:mac pro Core i5
jdk版本:java8
mango版本:1.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants