新手学ssh hibernate的问题 请高手指教 在线等
请问一下错误是什么原因? 查了半天没查出来 请高手不吝指教
public Member loginMember(Member member) {
String sql = " from member where member_name='"+member.getMemberName()+"'
and password='"+member.getPassword()+"'";
System.out.print("sql --------------------- :"+sql);
List list = new ArrayList();
list = memberDao.find(sql);
if(list.size()==1){
return (Member)list.get(0);
}
else
return null;
}
sql --------------------- : from member where member_name='1' and password='2'2008-5-31 21:54:19 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet 31ms threw exception
org.springframework.jdbc.BadSqlGrammarException: Bad SQL grammar [] in task 'Hibernate operation';
nested exception is java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from where (member_name='1' )and(password='2' )' at line 1"
java.sql.
SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from where (member_name='1' )and(password='2' )' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)
------解决方案--------------------
from语句后面跟的是类名,不是数据库里表的名字。
你试试from Member m where m.name=? and m.password=?