Recently, you need to manually write SQL statements directly into Java code and write SQL statements, and there are a few minor issues to be aware of.
First of all I wrote a few simple SQL statements, self-thought no problem, but the compilation of direct error.
1 String str = "INSERT into XXX (a,b,c) VALUES ('" A.geta () "', '" A.getb () "', '" a.getc () "');";
The study of a half-day discovery should be a connection string problem, the first modification after the assignment field before and after the "+" sign to complete the SQL statement. After correcting the code as follows
1 String str = "INSERT into XXX (a,b,c) VALUES ('" +a.geta () + "', '" +A.GETB () + "', '" +a.getc () + "');";
The original assignment to the field in the database needs to be ' "+ + "' The way to finish. OK, after compiling successfully, will run the result value of STR into SQL database test, no problem, think everything OK, results run again error. This self-obsessed, repeated testing, in the database with SQL statements to compare, no problem ah, now my last successful code put up, we see if there is any difference.
1 String str = "INSERT into XXX (a,b,c) VALUES ('" +a.geta () + "', '" +A.GETB () + "', '" +a.getc () + "')";
Yes, it is the last semicolon, the original in the Java statement can not be added to ordinary SQL statements, although there is no error in the database, but in Java must pay attention to this small problem.
Questions to note about writing SQL statements in Java code