mysql语法

SELECT * FROM t_student  WHERE  1=1 and stu_name LIKE %王%

[Err] 1064 - 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 '%王%' at line 1


注意字符是要带单引号的

SELECT * FROM t_student  WHERE  1=1 and stu_name LIKE '%王%'



if(stuName != null && !stuName.equals("")) {
System.out.println("stuName:"+stuName);
sql.append("and stu_name like ?");
paramList.add("'%"+stuName+"%'");
}


if(stuName != null && !stuName.equals("")) {
System.out.println("stuName:"+stuName);
sql.append("and stu_name like ?");
paramList.add("%"+stuName+"%");
}


USERNAME="root";
PASSWORD="root";
DRIVER="com.mysql.jdbc.Driver";
URL="jdbc:mysql://127.0.0.1:3306/imooc_pager";


  USERNAME="root";
PASSWORD="root";
DRIVER="com.mysql.jdbc.Driver";
URL="jdbc:mysql://127.0.0.1:3306/imooc_pager?useUnicode=true&characterEncoding=utf8";


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'stu_name like '%王%'and gender = 1' at line 1

StringBuilder sql = new StringBuilder("select * from t_student where 1=1"); //??1=1

if(stuName != null && !stuName.equals("")) {
System.out.println("stuName:"+stuName);
sql.append("and stu_name = ?");
paramList.add("%"+stuName+"%");
}

if(gender == Constant.GENDER_MALE || gender == Constant.GENDER_FEMALE) {
System.out.println("gender:"+gender);
sql.append("and gender = ?");
paramList.add(gender);
}
System.out.println(sql);


com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'stu_name = 'h'and gender = 1' at line 1

StringBuilder sql = new StringBuilder("select * from t_student where 1=1"); // where1=1 后面得加空格跟其他条件隔开

StringBuilder sql = new StringBuilder("select * from t_student where 1=1 ");



类似文章:其他原因的

http://www.itnose.net/detail/982537.html


http://ask.youkuaiyun.com/questions/170059


http://blog.youkuaiyun.com/vanezuo/article/details/6686089


http://blog.sina.com.cn/s/blog_6d70461d01018xul.html



class Y {

public static void main(String[] args) {
String s = "hello";
if(s=="hello") {
System.out.println("==相等hello");
}
if(s.equals("hello")) {
System.out.println("equals相等hello");
}

String snew = new String("new");
if(snew=="new") {
System.out.println("==相等");
}
if(snew.equals("new")) {
System.out.println("equals相等new");
}

//==相等hello
//equals相等hello
//equals相等new
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值