【发布时间】:2017-11-29 14:54:30
【问题描述】:
我不知道这部分的错误是什么,请帮忙
这是我的代码
public void addEmploye(Employe employe, Service service) throws SQLException{
int id_service = getServiceId(service);
if(nbrPersonnes(employe.getCin())!=0)
System.out.println("Employe deja existant verifier le cin");
else{
String SQL = "insert into Employe(post) "
+ "values ("
+ "'"+employe.getPost()+"')"
+ "insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_employe,id_service)"
+ "values('"+employe.getCin()+"',"
+ "'"+employe.getNom()+"',"
+ "'"+employe.getPrenom()+"',"
+ "'"+employe.getAdresse()+"',"
+ "'"+employe.getTel()+"',"
+ "'"+employe.getEmail()+"',"
+ "'"+employe.getPassword()+"',"
+ "0,"
+ " SELECT LAST_INSERT_ID() FROM `Personne`,"
+id_service+")";
if(id_service!=0)
try {
stmt = con.createStatement();
rs = stmt.executeUpdate(SQL);
} catch (SQLException e) {
System.out.println("addEmploye "+e.toString());
}
}
}
这是错误
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
addEmploye com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'insert into Personne(cin,nom,prenom,adresse,tel,email,password,id_directeur,id_e' at line 1
我的团队伙伴为 MSSQL 编写了这段代码,但我现在想在 Mysql SGBD 下使用它我发现这个问题有任何建议
【问题讨论】:
-
这两个语句之间没有空格。
+ "'"+employe.getPost()+"')" + "insert into Personne( -
即使没有空格,我也总是出现同样的错误
-
你能在同一个块中有 2 个插入吗?你至少不需要分号吗?
-
尝试打印出语句,看看它是否可以直接在 MySQL 中运行。
-
@TedTrippin no and no - SQL 语句中的分号无效(有些驱动不允许,有些则忽略)。