在写搭建服务器时,连接mysql数据库发生错误:
Unknown column ‘XXX’ in ‘where clause’…
【说明】:
测试所用数据库:
// 说明:uid为int类型,pwd为char类型
String sql = "select * from user_test where uid="+ID+" and pwd="+PW; // 错误写法,PW需要用引号
测试结果:
String sql = "select * from user_test where uid="+ID+" and pwd='"+PW+"'"; // 正确写法
测试结果:
总结:
sql中定义的类型是int型的可以不用加引号,但是如果是字符串类型的,必须加引号。