我在我的Java项目中使用MySQL Workbench和Netbeans。
将数据插入数据库时,显示错误:
; Expected Not a statement
这是Java代码:
public int adduser(String fname,String mname,String lname,String address,
String phone,String email,String designation,
String subject,String institute,String inemail,
String uname,String pwd,String utype)
{
int n=0;
try{
String sql=
"insert into user(user_name,password,type,specialize,f_name,m_name, " +
"l_name, address,phone,email,designation,institute,in_email) " +
"values('"+uname+"','"+pwd+"','"+utype+"','"+subject+"'," +
"'"fname"','"mname"','"lname"','"address"','"phone"','"email"','"designation"','"institute"','"inemail"')";
n = db.modifyingQueries(sql);
}
catch(Exception e)
{
}
return n;
}
这个错误是什么意思?我的SQL语句出了什么问题?
答案 0 :(得分:5)
您错过了+
符号串联的字符串。
String sql="insert into user(user_name,password,type,specialize,f_name,m_name,l_name,"
+ "address,phone,email,designation,institute,in_email)values('"+uname+"','"+pwd+"','"+utype+"','"+subject+"',"
+ "'"+fname+"','"+mname+"','"+lname+"','"+address+"','"+phone+"','"+email+"','"+designation+"','"+institute+"','"+inemail+"')";