James MV
James MV

Reputation: 8717

ResultSet to String java?

I'm just after a way to convert a ResultSet to string I've tried:

toReturn = result.getString(0);

I'm only after a proof that its working and thought this would be all that I need to return it via:

writer.write(toReturn);

TIA

Upvotes: 3

Views: 11362

Answers (2)

Sully
Sully

Reputation: 14943

if toReturn is a string, then calling getString(indx) will return a string and you will get an error on that line if it was assigning a different type.

Upvotes: 0

skaffman
skaffman

Reputation: 403481

JDBC column indexes start at 1, not zero, so try result.getString(1)

Upvotes: 6

Related Questions