0

$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 'null, null, null, 98-4B-E1-A9-C5-82, null)' at line 1$

Error that i got when this is executing

st.executeUpdate("INSERT INTO gameservers" + "VALUES (null, null, null, "+macAddress+", null)");

And my sql:

CREATE TABLE IF NOT EXISTS `gameservers` (
  `server_id` int(11) NOT NULL default '0',
  `hexid` varchar(50) NOT NULL default '',
  `host` varchar(50) NOT NULL default '',
  `macAddress` varchar(50) NOT NULL default '',
  `firstTime` int(1) NOT NULL default '0',
  PRIMARY KEY  (`server_id`)
) ;

Any idea?

2
  • 1
    You should use prepared statements rather than constructing query strings with embedded values via string concatenation: then many of these problems would not occur. Commented Sep 11, 2012 at 23:14
  • st.executeUpdate("INSERT INTO gameservers " + "VALUES (null, null, null, "+macAddress+", null)"); you are missign a space before VALUES (after table name) Commented Oct 6, 2012 at 13:12

2 Answers 2

2

You need a space after gameservers and you need to put macAddress in quotes. At least.

"INSERT INTO gameservers " + "VALUES (null, null, null, '"+macAddress+"', null)"
Sign up to request clarification or add additional context in comments.

Comments

1

macAddress is varchar, so it should be wrapped in single quote.

"VALUES (null, null, null, '"+macAddress+"', null)"

1 Comment

@user1663856: Don't forget to accept applicable answers. Accepting answers will encourage community to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.