JAVA往oracle数据库插一条记录刚开始很快 ,可是后来不知道怎么搞的,插一条记录要5分钟,我哭,什么原因啊?

解决方案 »

  1.   

    是不是你的代码里面有的地方 打开了连接 没有close啊 
    以前我也有遇到过的
      

  2.   

    给出code比较好分析,还有oracle中如果这个插入有用到触发器,存储过程,也一并将其code给出。
      

  3.   

        public JDBConnection() {
      try {
        Class.forName(dbDriver).newInstance();         //加载数据库驱动
        System.out.println("数据库加载成功");
      }
      catch (Exception ex) {
        System.out.println("数据库加载失败");
      }
    } //创建数据库连接
     public boolean creatConnection() {
       try {
       OracleDataSource ds = new OracleDataSource();
       ds.setURL(url);
       ds.setUser(userName);
       ds.setPassword(password);
       con=ds.getConnection();
       System.out.println("连接数据库成功");
       }
       catch (SQLException e) {
       }
       return true;
     }
    //对数据库的增加、修改和删除的操作
     public boolean executeUpdate(String sql) {
       if (con == null) {
         creatConnection();
       }
       try {
         Statement stmt = con.createStatement();
         System.out.println("即将执行操作");
        int iCount = stmt.executeUpdate(sql);
        System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
       }
       catch (SQLException e) {    }
       return true;
     }
    //关闭数据库的操作
     public void closeConnection() {
       if (con != null) {
         try {
           con.close();
           System.out.println("关闭数据库成功");
         }
         catch (SQLException e) {
           e.printStackTrace();
         }
         finally {
           con = null;
         }
       }
     }代码就是这样子的,有问题么 ?
      

  4.   

    org.apache.catalina.loader.WebappClassLoader findResourceInternal
    信息: Illegal access: this web application instance has been stopped already.  Could not load .  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
    出现这样的信息
      

  5.   

    插入数据的代码
    connection = new JDBConnection();
    for(int i = 0;i < 10;i++)
    {
    int answerid = i  + 1;
    sql = "insert into answer values (" + answerid + ",701," + str1[i] + "," + str3[i]+ ",'杭州')";
    connection.executeUpdate(sql);
    }
    connection.closeConnection();
      

  6.   

    OracleDataSource ds = new OracleDataSource();
      ds.chinese wholesalers(url);
      ds.setUser(userName);
      ds.setPassword(password);
      con=ds.getConnection(); 
      

  7.   

    this web application instance has been stopped already.  Could not load .
    这里说得很明白了啊!
      

  8.   

    话说我重启电脑后再插入数据开始速度很快,过会又慢了,加了关闭Statement的代码了 
      

  9.   

    有完整代码吗?把Statement换成PrepareStatement,用batch做,使用绑定变量,不要多次打开关闭链接。sql = "insert into answer values (?,'杭州')"; 
    conn = db.getConnection(); 
    ps   =   conn.prepareStatement(sql); 
    for(int i = 0;i < 10;i++) 

    int answerid = i  + 1; 
    ps.setString(1, " + answerid + ",701," + str1[i] + "," + str3[i]+ ");
    ps.addBatch();

    ps.executeBatch();
      

  10.   

    PrepareStatement比Statement的效率高不少
      

  11.   

    数据插入慢,在Oracle中可能是首先程序中未及时关闭连接,造成数据库死锁。还有如果你用的是PL/SQL等查询分析器的话,你在查询分析器中执行了相关的修改或删除操作,但是你没有提交你的修改,照样会照成ORACLE死锁。我之前遇到过,呵呵 只能提供这么2点我的经历,希望能帮到你