为什么这段代码运行时有时会很快,而有时会等很久的时间,有时还会运行不下去,像死了机一样。 你的数据库是不是公用的?有人在对同一个表写操作,没有commit,你的执行语句就要等在那里 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 for (int i = 0; i < count; i++)是不是你的这个count有时大有时小呀?还有啊,有时执行慢是因为系统的缘故 count 当然有时大有时小啊,不然也不会有这种语句了。执行慢不是系统的缘故! 没有commit,你的执行语句就要等在那里,这种情况应该如何办呢? Statement statement = con.createStatement(); String newData = "insert into football values ('" + match[i].leagueName ------------------------------------------------------------------------------建议把变量定义的语句放到循环的外面,内存里实例化了太多的对象,速度就会慢下来。在外面定义变量,对象才能重用。 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //加载数据库相应的驱动程序 Connection con = DriverManager.getConnection(dbUrl, user, password); //建立连接 con.setAutoCommit(false); Statement statement = con.createStatement(); //System.out.println("建立连接!"); for (int i = 0; i < count; i++) { //System.out.println("建立连接!"); String tmp = "" + num; //Statement statement = con.createStatement(); String newData = "insert into football values ('" + match[i].leagueName + "','" + match[i].matchTime + "','" + match[i].state + "','" + match[i].voiceCodeA + "','" + match[i].voiceCodeB + "','" + match[i].matchScoreA + "','" + match[i].matchScoreB + "','" + match[i].halfScoreA + "','" + match[i].halfScoreB + "','" + match[i].matchEvent + "','" + match[i].matchID + "','" + tmp + "','" + count + "','" + match[i].redA + "','" + match[i].redB + "')"; //statement.executeUpdate(newData); statement.addBatch(newData); // statement.close(); } statement.executeBatch(); //运行到此就不动了! con.commit();//从此段开始不能运行,程序停在上面。 statement.close(); con.close();这是怎么一回事?救救我吧 statement.executeBatch() 返回值是多少? java socket 拆包与组包 swing 如何实现如下的状态栏效果? 不解,ArrayList添加一组元素 请高手帮忙解答 是这样一个问题,我从MYSQL数据库里的一个表里的100w多条数据导入另外一个数据库的表里(hsql),改如何操作, 大家帮忙看看--数组排序后删除重复元素的问题! 有高手可以帮我写一写,服务器邓注释吗? 请教一个问题:抽象类和接口有什么不同? 初学java,想做一记事本,不知道怎么实现“打开”部分?求助! 位运算 向各位大侠请教一个用jaxp包生成xml对象的问题 利用 RandomAccessFile向一个文件中写入信息时,为什么出现乱码?
是不是你的这个count有时大有时小呀?还有啊,有时执行慢是因为系统的缘故
String newData = "insert into football values ('" + match[i].leagueName
------------------------------------------------------------------------------
建议把变量定义的语句放到循环的外面,内存里实例化了太多的对象,速度就会慢下来。在外面定义变量,对象才能重用。
con.setAutoCommit(false);
Statement statement = con.createStatement();
//System.out.println("建立连接!");
for (int i = 0; i < count; i++) {
//System.out.println("建立连接!");
String tmp = "" + num;
//Statement statement = con.createStatement();
String newData = "insert into football values ('" + match[i].leagueName +
"','" + match[i].matchTime + "','" + match[i].state + "','" +
match[i].voiceCodeA +
"','" + match[i].voiceCodeB + "','" + match[i].matchScoreA + "','" +
match[i].matchScoreB + "','" + match[i].halfScoreA + "','" +
match[i].halfScoreB +
"','" + match[i].matchEvent + "','" + match[i].matchID + "','" + tmp +
"','" +
count + "','" + match[i].redA + "','" + match[i].redB + "')"; //statement.executeUpdate(newData);
statement.addBatch(newData);
// statement.close(); } statement.executeBatch(); //运行到此就不动了!
con.commit();//从此段开始不能运行,程序停在上面。
statement.close();
con.close();这是怎么一回事?救救我吧