在工作中需要用到查询语句:
String userName = name;
System.out.println("loginName:"+name);
System.out.println("password:"+password);
List<User> list = new ArrayList<User>();
list = new ArrayList<User>();
con = new DBUtlie().getConnection();
String sql = "select * from s_user where loginName = '"+userName+"'";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
开始的时候,我把sql语句写成这样的形式:
String sql = "select * from s_user where loginName = userName;
结果报错,说找不到列userName.我想不是让你找userName列啊,userName是我自己的定义的变量。原来,需要在user外加双层双引号,才可以。