Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update SQL Problem... 1

Status
Not open for further replies.

B14speedfreak

Technical User
Mar 23, 2006
182
0
0
Hi all,

My thanks in advance for all help given. I am trying to code a bit of a java app up, and I am sort of learning as I go, so please bear with me for my lack of experence.

I set a table in a database using the following syntax:

CREATE TABLE Instructor(
FirstName VARCHAR(20) NOT NULL,
Surname VARCHAR(20) NOT NULL,
Title VARCHAR(20) NOT NULL,
DOB DATE NOT NULL,
Address1 VARCHAR(50) NOT NULL,
Address2 VARCHAR(50) NOT NULL,
Address3 VARCHAR(50) NOT NULL,
PostCode VARCHAR(50) NOT NULL,
Telephone INT NOT NULL,
Mobile INT NOT NULL,
Email VARCHAR(50) NOT NULL,

PRIMARY KEY(FirstName, Surname));

I create a record with some information (firstname = emma, surname = newton)...

I am then trying to update a record that has been created as follows:

UPDATE instructor

SET firstname = 'Emma',
surname = 'Newton',
title = 'Newton',
dob = '1975-5-26',
address1 = 'Debenhams',
address2 = 'Centre of Manchester',
address3 = 'Manchester',
postcode = 'M67 2QR',
telephone = 1234, mobile = 324,
email = 'emma2@emma.com',

WHERE firstname = 'Emma',
AND
surname = 'Newton' ;

When I enter this syntax through the msyql server prompt they run fine. However when I do the update I get the following SQL errors (handed to me by java as exceptions):

sql is: UPDATE instructor SET firstname = 'Emma', surname = 'Newton', title = 'Newton', dob = '1975-5-26', address1 = 'Debenhams', address2 = 'Centre of Manchester', address3 = 'Manchester', postcode = 'M67 2QR', telephone = 1234, mobile = 324, email = 'emma2@emma.com', WHERE firstname = 'Emma', AND surname = 'Newton' ;

connected

SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE firstname = 'Emma', AND surname = 'Newton'' at line 1

SQLState: 42000

VendorError: 1064

Is this something to worry about, or is this just a random java thing?

Any ideas anyone,

thanks again, and seasons greatings,



B14... aka... Marky Mark... the frozen monkey in the server room...
 
leave out these two commas:
... , WHERE firstname = 'Emma', AND surname = 'Newton' ;
 
That seemed to resolve the problem, thankyou.

Thanks again and seasons greatings,



B14... aka... Marky Mark... the frozen monkey in the server room...
 
No problemo...

B14... aka... Marky Mark... the frozen monkey in the server room...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top