Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert into statement using JDBC

 
Kassi Hill
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write an SQL INSERT INTO statement to insert data into a table in MS Access. The method I am writing is accepting an object and then getting the specific information needed to insert into the database out of the object. I have having trouble with the wording of the SQL statement itself and I would appreciate any help.
int qID
String qText
boolean qType
int qCorrect
sql = "INSERT INTO Question(qID, qText, qType, qCorrect)
VALUES(+qID, +"qText", + qType, + qCorrect)");

I also need to write an UPDATE statment based on the same idea, where the method will be sent an object. Could someone give me an example of how the sql statement will look?
Thanx again!!!
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

If you run this command alot, I recommend you to use PreparedStatement, which is alot cleaner.
[ October 15, 2003: Message edited by: Adrian Yan ]
 
Kassi Hill
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you VERY much, this appears to have solved my problem. Would the
update statement be the same excet using UPDATE instead of INSERT INTO??
 
Prasma Kankut
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kassi Hill:
Would the
update statement be the same excet using UPDATE instead of INSERT INTO??

No. The UPDATE query will look like this
UPDATE table_name SET column_name = value
Be sure to add a WHERE clause, so that only the corresponding row(s) will be updated. Else you will end up updating all the rows in the table.
The syntax will be
UPDATE table_name SET column_name = value WHERE condition
[ October 15, 2003: Message edited by: Prasma Kankut ]
 
Kassi Hill
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx again for your help. If I understand correctly, my Upate statement should look something like:

sql = "UPDATE Question SET qID, qText, qType, qCorrect = VALUES(" + qID + "," + qText + "," + qType + "," + qCorrect + ") WHERE qID" = qID;
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kassi Hill:
Thanx again for your help. If I understand correctly, my Upate statement should look something like:

sql = "UPDATE Question SET qID, qText, qType, qCorrect = VALUES(" + qID + "," + qText + "," + qType + "," + qCorrect + ") WHERE qID" = qID;

"UPDATE Question SET qID = " + qID + ", qText = " + qText + "........
[ October 15, 2003: Message edited by: Gregg Bolinger ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic