$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?
Keith Randall
23.3k3 gold badges38 silver badges54 bronze badges
-
1You should use prepared statements rather than constructing query strings with embedded values via string concatenation: then many of these problems would not occur.user207421– user2074212012年09月11日 23:14:02 +00:00Commented 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)transilvlad– transilvlad2012年10月06日 13:12:59 +00:00Commented Oct 6, 2012 at 13:12
2 Answers 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)"
answered Sep 11, 2012 at 19:19
Matthew Farwell
61.9k18 gold badges134 silver badges174 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
macAddress is varchar, so it should be wrapped in single quote.
"VALUES (null, null, null, '"+macAddress+"', null)"
answered Sep 11, 2012 at 19:19
kosa
66.8k15 gold badges135 silver badges170 bronze badges
1 Comment
kosa
@user1663856: Don't forget to accept applicable answers. Accepting answers will encourage community to help you.
default