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 'Name,Enrol no,Department,Mobile No,Email) values(Effie,1051,CE,123456789,121...' at line 1
The above exception is displaying. I don't know what I'm doing wrong, but here is the code:
String Create()
{
String sql;
Scanner sc = new Scanner(System.in);
System.out.println("Enter name:");
String name = sc.nextLine();
System.out.println("Enter enrl:");
long enrl = sc.nextInt();
sc.nextLine();
System.out.println("Enter department:");
String dept = sc.nextLine();
System.out.println("Enter mobile no:");
String mono = sc.nextLine();
System.out.println("Enter mail:");
String mail = sc.nextLine();
sql="Insert into stud_details(First Name,Enrol no,Department,Mobile No,Email) values("+name+","+enrl+","+dept+","+mono+","+mail+");";
return sql;
}
The above code is written in class "demo" and I've called it in the main class containing PSVM. I cannot find the mistake here.