• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making an SQL query string and using Index

 
Rod Hittle
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was stumbling along and getting index errors while trying to write a string variable that contained the SQL query I wanted and then using the Index method to try to pull the data out.
I found in my string I needed those spaces after the words and that it was nice to place a comma before a word(column name) just as I would write the query as I do on the mainframe.
Using INDEXING to pull the data from the results to variables in the Java code was not completely clear to me. I was unsure if the index was to the order in the table and if the index started with 0 or 1.
From playing around it seems the index is to the order that the select SQL statement is written and not the table itself. Between the index thing and being careful to put spaces and commas in the string for the SQL statement I got a lot of trial and error. I still may have something wrong but it works now. I welcome any comments of syntax style or any other suggestion.



SQL style and INDEX.jpg
[Thumbnail for SQL style and INDEX.jpg]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the future, please post code using code tags (see UseCodeTags). Screen shots are OK, but include the code as text as well.

Rod Hittle wrote:I was unsure if the index was to the order in the table and if the index started with 0 or 1.

JDBC indexes start with 1, and are the order in the select statement. Why not use the column names rather than indexes?

Between the index thing and being careful to put spaces and commas in the string for the SQL statement I got a lot of trial and error.

Yes the SQL statement must follow correct syntax; just like any programming language.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic