title: Java/SQL - executeUpdate() hangs and causes OutOfMemoryException
body: <p>I'm trying to perform a relatively simple insert into my table, but the executeUpdate() method hangs until the program crashes with an OutOfMemoryException. I've successfully performed inserts on the SQL Server Management Studio, and I've set the database offline and back online, so I don't think there's any way the table could be locked. I'm also printing out my tokens, and none of them are null. </p>
  
  <p>Does anything look suspicious in my code?</p>
  
  <pre><code>if(commandCode.equals("RV")){
      StringTokenizer tokens = new StringTokenizer(fullLine,"^");
  
      String itemCallNumber=null;
      String itemCurrentLocation=null;
      String itemFormat=null;
      String itemHomeLocation=null;
      String itemLibrary=null;
      String itemType=null;
      String itemCat1=null;
      String itemCat2=null;
      String itemCat3=null;
      Integer itemPubYear=null;
      String stationLibrary=null;
      String userProfileName=null;
      String userCat1=null;
      String userCat2=null;       
      String userZipCode=null;
      String userLibrary=null;
      java.sql.Date userBirthdate=null;
      String clientType = null;
  
  
      while(tokens.hasMoreTokens()){
          String token = tokens.nextToken();
          System.out.println(token);
          if(token.startsWith("UZ")){
              String dateString = token.substring(2);
              SimpleDateFormat format = new SimpleDateFormat("M/d/yyyy");
              Date date = format.parse(dateString);
  
              userBirthdate=new java.sql.Date(date.getTime());;
          }
          if(token.startsWith("PG")){
              userCat1=token.substring(2);
          }
          if(token.startsWith("PH")){
              userCat2=token.substring(2);
          }
  
          if(token.startsWith("PE")){
              userProfileName=token.substring(2);
          }
  
          if(token.startsWith("UM")){
              userLibrary=token.substring(2);
          }
          if(token.startsWith("UB")){
              userZipCode=token.substring(2);
          }
  
          if(token.startsWith("IQ")){
              itemCallNumber=token.substring(2);
          }
          if(token.startsWith("IL")){
              itemCurrentLocation=token.substring(2);
          }
          if(token.startsWith("IK")){
              itemFormat=token.substring(2);
          }
          if(token.startsWith("IN")){
              itemHomeLocation=token.substring(2);
          }
          if(token.startsWith("NS")){
              itemLibrary=token.substring(2);
          }
          if(token.startsWith("IG")){
              itemType=token.substring(2);
          }
          if(token.startsWith("NX")){
              itemCat1=token.substring(2);
          }
          if(token.startsWith("NY")){
              itemCat2=token.substring(2);
          }
          if(token.startsWith("0A")){
              itemCat3=token.substring(2);
          }
          if(token.startsWith("IF")){
              itemPubYear=Integer.parseInt(token.substring(2));
          }
          if(token.startsWith("FE")){
              stationLibrary=token.substring(2);
          }
  
          if(token.startsWith("dC")){
              clientType=token.substring(2);
          }
  
      }
  
  
      String insert = "INSERT INTO dbo.RenewItem Values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      PreparedStatement insertPS = connection.prepareStatement(insert);
  
      //These come from earlier in the code and are verified to be correct
      insertPS.setInt(1, id);
      insertPS.setTimestamp(2, ts);
  
      insertPS.setString(3, itemCallNumber);
      insertPS.setString(4, itemCurrentLocation);
      insertPS.setString(5, itemFormat);
      insertPS.setString(6, itemHomeLocation);
      insertPS.setString(7, itemLibrary);
      insertPS.setString(8, itemType);
      insertPS.setString(9, itemCat1);
      insertPS.setString(10, itemCat2);
      insertPS.setString(11, itemCat3);
      insertPS.setInt(12, itemPubYear);
      insertPS.setString(13, stationLibrary);
      insertPS.setString(14, userProfileName);
      insertPS.setString(15,userCat1);
      insertPS.setString(16, userCat2);
      insertPS.setString(17, userZipCode);
      insertPS.setString(18, userLibrary);
      insertPS.setDate(19, userBirthdate);
      insertPS.setString(20,clientType);
  
      insertPS.executeUpdate();
  </code></pre>
  
  <p><strong>EDIT:</strong> I've been able to greatly isolate the problem. It has to do with a surrounding SELECT * on a big table. In the below code, selectPS.close() is reached but the method never returns. </p>
  
  <pre><code>        final Connection connection = DriverManager.getConnection(url);
  
          String select = "SELECT * FROM dbo.SirsiStat";
          PreparedStatement selectPS = connection.prepareStatement(select);
          ResultSet rs = selectPS.executeQuery();
          System.out.println("here");
          selectPS.close();
  </code></pre>