0

我在我的 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 语句有什么问题?

4

1 回答 1

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+"')";
于 2013-08-14T05:41:37.233 回答