Hi everyone. Believe it or not, I've been fighting with my simple little java program all day long and cannot figure this out and java tutorials don't seem to help. I'm just getting started with java and mysql so I know next to nothing. I'm using netbeans 6.9.1 to create my java GUI program. I have created and successfully run a '.sql' file. I have two tables and have initialized the database with one record in one of the tables. I can see the data from netbeans IDE services so I know the data is there. In my program, I can successfully open and connect to my database. The problem is, I don't know how to retrieve a specific record from the table.
Here's a code snippet where I attempt to get a specific record:
'numID' is an integer variable previously filled. 'accountID' is an integer field in 'Customers' table. First of all, is this query correct? If it is, how do I know that a record with accountID equal to numID was found and how do I read the data?
“I tried being reasonable, I didn't like it.”
Jesper de Jong wrote:I guess you want to do a query which looks for a record with a specific number. The syntax with @numID is not going to work. Is numID a variable in your program? Where did you learn that syntax?
It's stored procedure syntax. You use @ for variables in stored procedures.
It's next() you should use. This goes to the next record (to the first if called for the first time) and returns true, or does nothing and returns false if you've already went through all records. Usually you call next() in a loop, but if you know there's going to be only zero or one record then if is also good.