I’m writing a java socket app that allows a client to communicate with a server, one of the other requirements is that it also needs to initialize JDBC. I believe I have wrote my JDBC connection method correctly, and my insert statement has worked like this on similar projects. It might be a simple mistake as i’m not using an IDE, can someone tell me what is wrong with my SQL statement? All the info is right, but it won’t compile.
Error:
C:\Users\imallin\My Documents> javac provider.java
Provider.java:88 ';' expected
String sql = "Insert INTO 'users' ('ID', 'firstName') VALUES ("123","123")";
Your immediate problem is that you need to escape the double quotes that are in your string. This is because when the compiler see’s another
"it thinks it is the end of the String definition and exepcts a semi-colon.Now that the Java compiler is happy, you will have SQL-related issues.
In general with SQL, you will want to use single quotes to represent a string. It appears MySQL specifically allows double quotes, but only when the SQL QUOTES ANSI mode is not set. So it is best to use single quotes to represent strings here.
Here is what you probably want, assuming that the
IDcolumn is an integer, and that thefirstNamecolumn is a string/varchar.