可以用一个连接建立两个Statement

解决方案 »

  1.   

    创建connection时错误,我查一下
      

  2.   

    我在DBTools这个类里面建立连接用的下面的方法的,麻烦看看这样建行吗?
      /**建立数据库连接
       *返回数据库连接对象
       *@return con
       */
      public static Connection getNewConnection()
      {
        try
        {
          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
          Connection con=DriverManager.getConnection(dburl);
          con.setAutoCommit(false);
          Connection connection = con;
          return connection;
        }
        catch(Exception e)
        {
          error("getNewConnection error:"+e.getMessage());
        }
        Connection connection1 = null;
        return connection1;
      }  /**返回数据库连接对象
       * @return con
       */
      public synchronized static Connection getCurCon()
      {
        if(binit)
        {
          try
          {
            if(con.isClosed())
            {
              binit=false;
              return getCurCon();
            }
            else
              return con;
          }
          catch(Exception e)
          {
            error("connection error:"+e.getMessage());
          }
        }
        con=getNewConnection();
        binit=true;
        return con;
      }
      

  3.   

    如果设置了conn.setAutoCommit(false)把它去掉