Menu

Iterating over Each Row updating values

Help
2017-06-13
2017-06-13
  • Patrick Hentschel

    Hi guys, I need to format Phonenumbers inside Access and already got the Data and formatted all phonenumbers inside an Arraylist, now I need to update the phonenumbers with the new formatted Values but the update function does not work. While Debugging I noticed that my ResultSet seems to be empty, but reparing the AccessDatabase did not help.

        public void executeQueryPhoneNumber(String tableName, String columnName)
        {
            this.actualColumn = columnName;
            this.phonenumberColumn = columnName;
            this.table = tableName;
            try {
                this.query = this.connection.createStatement();
                this.resultSet = query.executeQuery("SELECT " + this.phonenumberColumn + " FROM " + this.table);
                appendItems(this.phoneNumbers, this.resultSet);
            } catch (SQLException e) {
                System.err.println(e.getMessage() + "\nErrorCode: " + e.getErrorCode());
            }
    
        }
    

    This is the working Query to get the phonenumbers

        public void updatePhonenumberColumn()
        {
            try {
                 int i = 0
                 while(this.resultSet.next()) {
                 String sql = "UPDATE " + this.table + " SET " + this.phonenumberColumn + "=? " + " WHERE " + this.idColumnName + = "=?";
                 PreparedStatement preparedStatement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATEABLE);
                 preparedStatement.setString(1, this.phonenumbers.get(i));
                 preparedStatement.setString(2, Integer.toString(i));
                 preparedStatement.executeUpdat();
                 i++;
            } catch (SQLException e) {
                System.err.println(e.getMessage() + "\nErrorcode: " + e.getErrorCode());
            }
        }
    
     
  • Gord Thompson

    Gord Thompson - 2017-06-13

    Answered on Stack Overflow.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.