Jump to content

What is happening in this code?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
williamevanl

williamevanl

    Learning Programmer

  • Members
  • PipPipPip
  • 61 posts
ps = switchboard.connection.prepareStatement("select * from contents where containerId = 'fbatchcombo1'")

          switchboard.resultSet = ps.executeQuery();

          while switchboard.resultSet.next():  

            results = switchboard.resultSet.getString(3)

            f.write (results)


I'm using jython 'I think' and I have limited access to (the cursor) 'whatever that is'. It appears as though I have limited access because the connection string isn't available to me so I think I have to make due with this switchboard.connection. My simple question is why does the above code only work with the while loop in there? Why can't I just have the results = switchboard.resultSet.getString(3)

The hard question is where can I find information on any of this?

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
switchboard.resultSet is apparently an iterator, and when it's next() method is called it changes it's internal state to reflect the next Result in the ResultSet. If you only put in results= switchboard.resultSet.getString(3) that would only return the getString value of the first result in resultSet, not all of them. It then writes each result from resultSet.getString(), and if it had not been in a loop it would have only written one result to wherever f is pointing. I'm not immediately familiar with all the SQL tools for Python, but that's what the code appears to be doing.
Wow I changed my sig!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users