Java com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列';电子邮件';在';其中第'条;
具有表名Java com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:未知列';电子邮件';在';其中第'条;,java,mysql,spring,hibernate,Java,Mysql,Spring,Hibernate,具有表名emptab代码的格式化员工如下: Hibernate: select employee0_.empid as empid0_, employee0_.empmail as empmail0_, employee0_.empmobile as empmobile0_, employee0_.empname as empname0_, employee0_.emppassword as emppass
emptab
代码的格式化员工如下:
Hibernate:
select
employee0_.empid as empid0_,
employee0_.empmail as empmail0_,
employee0_.empmobile as empmobile0_,
employee0_.empname as empname0_,
employee0_.emppassword as emppassw5_0_
from
emptab employee0_
where
email=?
and employee0_.emppassword=?
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown
column 'email' in 'where clause'
在
?
周围加上单引号”
,因为电子邮件和密码都是字符串,然后重试
@Entity
@Table(name="emptab")
public class Employee {
@Id
@Column(name="empid")
private int id;
@Column(name="empname")
private String name;
@Column(name="emppassword")
private String password;
@Column(name="empmail")
private String mail;
@Column(name="empmobile")
private int mobile
}
String hql=“from”+Employee.class.getName()
+“作为employee0,其中employee0.empmail=?和employee0.emppassword=?”;
List emplist=ht.find(hql、电子邮件、pwd);
您的查询应该是:
String hql="from "+ Employee.class.getName()
+ " AS employee0_ where employee0_.empmail = ? and employee0_.emppassword=? ";
List<Employee> emplist=ht.find(hql,email,pwd);
确保数据库中的Employee entity和Employee表中已经存在电子邮件和密码字段。问题在于hql查询
String hql="from "+ Employee.class.getName()
+ " e where e.mail= ? and e.password=? ";
String hql=“from”+Employee.class.getName()
+“其中电子邮件=?和密码=?”;
List emplist=ht.find(hql、电子邮件、pwd);
在上面的查询中,“email”字段不在Employee类中,请将查询更改为
String hql="from "+ Employee.class.getName()
+ " where email= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);
String hql=“from”+Employee.class.getName()
+“其中邮件=?和密码=?”;
List emplist=ht.find(hql、电子邮件、pwd);
仔细检查,强烈建议,异常表示找不到
电子邮件
,您的员工
类中没有此类属性,实际上是邮件
,因此请像这样更改您的查询
String hql="from "+ Employee.class.getName()
+ " where mail= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);
共享您的Employee.java code您可以共享mappingEntity表(name=“emptab”)公共类Employee{@Id@Column(name=“empid”)private int Id;@Column(name=“empname”)private String name;@Column(name=“emppassword”)private String password;@Column(name=“empmail”)private String mail;@Column(name=“empmobile”)private int mobile;添加有问题的员工代码,而不是在注释中。编辑您的问题我在员工类中找不到您在querytried但新错误org.hibernate.QueryParameterException中指定的属性电子邮件。位置超出声明的序号参数的数量。请记住序号参数是基于1的!位置:1
String hql="from "+ Employee.class.getName()
+ " where mail= ? and password=? ";
List<Employee> emplist=ht.find(hql,email,pwd);
String hql="from "+ Employee.class.getName() + " where mail= ? and password= ? ";