Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about JDBC

 
Lee Sigauke
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a snippet of some JDBC code I wrote, I want to know what I have to put in the while block to iterate the result, I've seen examples of JDBC code but have no idea how you choose what to put in the while block and how it helps with the final result, can anyone explain this to me ?

My code




Example code

 
Tim Moores
Bartender
Posts: 3136
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe start with the JDBC tutorial: http://docs.oracle.com/javase/tutorial/jdbc/index.html
 
Bill Johnston
Ranch Hand
Posts: 201
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee Sigauke wrote:Here is a snippet of some JDBC code I wrote, I want to know what I have to put in the while block to iterate the result, I've seen examples of JDBC code but have no idea how you choose what to put in the while block and how it helps with the final result, can anyone explain this to me ?

My code

Example code

If name and age are columns in the people table, then that is why they are extracted in the while loop. What columns are available to you from the titles table? Do a query on them and see. In your JDBC code you can also do this:
But do continue to read up as suggested.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't just get all columns and guess what they mean. You should instead ask someone who actually knows. That could be your DBA, architect or some other colleague.

You should also stop using "SELECT *". See this for more information.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:You shouldn't just get all columns and guess what they mean. You should instead ask someone who actually knows. That could be your DBA, architect or some other colleague.

You should also stop using "SELECT *". See this for more information.


Rob's right: read up on SQL and JDBC, and don't use "SELECT * FROM ..."

And your "SELECT *, FROM Titles" won't work anyway because you have a trailing comma before your "FROM...".
 
Lee Sigauke
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your input, I got my code working and yes the comma was a mistake. But I understand what's going on now.
 
Rob Spoor
Sheriff
Pie
Posts: 20753
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic