-2

I'm getting a cannot find symbol error and it points to the period right in rs.getChars(1) This code is all within a try{}.

There are three columns in the view table, title, item_id, and name. I'm just trying to query it but get a cannot find symbol on the line inside the start of the while loop.

PreparedStatement pstmt= 
conn.prepareStatement("SELECT * FROM Film_Sound_Track");
ResultSet rs = pstmt.getResultSet();

while(rs.next()){
    char item_id = rs.getChars(1);
}

rs.close();
pstmt.close();
Roman C
  • 49,761
  • 33
  • 66
  • 176
user2318083
  • 567
  • 1
  • 8
  • 27
  • 1
    There is no such a method as `getChars(int)`. There are however methods like `getString(String columnLabel)` and `getString(int columnIndex)`. – Tiny Nov 13 '14 at 20:35
  • I'd like to suggest you familiarize yourself with the [Java API docs](https://docs.oracle.com/javase/8/docs/api/). You could have answered this yourself by reading the API and noticing there is no such method. – Mark Rotteveel Nov 14 '14 at 07:43

1 Answers1

2

java.sql.ResultSet does not have a method getChars. You could use the getString method to retrieve a String and then extract the char from it:

char item_id = rs.getString(1).charAt(0);
Mureinik
  • 297,002
  • 52
  • 306
  • 350