View Single Post
  #1 (permalink)  
Old August 4th, 2003, 07:46 PM
wslyhbb wslyhbb is offline
Registered User
Join Date: Aug 2003
Location: Zion, IL, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to wslyhbb Send a message via MSN to wslyhbb Send a message via Yahoo to wslyhbb
Default help needed with a SQL select statement problem

I am using Java to access information in a MySQL database, I created the following PreparedStatement:
PreparedStatement selectCurrentValue = databaseConnection.prepareStatement("SELECT ? FROM cardCatalog WHERE callNumber = ?");
Then I do (where "title" is the name of a column in the table, and callNumber.getText(), callNumber is a JTextField variable, .getText() gets the text from the text field in my GUI:
selectCurrentValue.setString(1, "title");
selectCurrentValue.setString(2, callNumber.getText());
ResultSet rs = selectCurrentValue.executeQuery();
      Vector values = new Vector(1);
      // create a vector to hold the results
      Vector vector = new Vector(1);
      // iterate through records
         // make sure values is empty
         // iterate through columns
         for(int i = 1; i <= 1; i++)
         // trim vector to size
         // add vector to vector
      // trim vector to size
      String currentValue = ((Vector)resultVector.elementAt(0)).elementAt(0).t oString();
After all of this executes, currentValue is "title", but that is not what should happen, it should have retrieve the information from column named title in the database. However, I can execute:
PreparedStatement selectCurrentValue = databaseConnection.prepareStatement("SELECT title FROM cardCatalog WHERE callNumber = ?");
selectCurrentValue.setString(1, callNumber.getText());
and gets the current value out of the result set as I did above I get "Java Security Handbook" which is the value stored in column title in the database for the call number I enter. Therefore, the callNumber.getText(); statement is obviously executing correctly, but why the other statement returns whatever string I pass the first question mark, I do not understand. What do I need to do to get it to work the way it should? What am I doing wrong? The goal is that I could pass it the column "title" or "author" or any column I want to get the current value in the database of. If anyone can help, it would be greatly appreciated. Thanks in advanced.