帮忙看个JSP页面里的查询语句
sqls= "SELECT price,ticketname,stock,sale FROM tickets as a,prices as b WHERE a.ticketid= "+newticket.getId()+ "and a.ticketid=b.ticketid and b.ticketblock= "+newticket.getTicketbolck()+ " ";
JSP里这样的查数据库语句可以吗,注意WHERE后面的那些 可以查出值吗 引号有没有问题
------解决方案--------------------没有问题。
只要你的数据类型符合sql标准就行
------解决方案--------------------SQL里面最后为什么要+ " "?
where的条件值为null怎么办???
------解决方案--------------------有问题的,
sqls= "SELECT price,ticketname,stock,sale FROM tickets as a,prices as b WHERE a.ticketid= "+newticket.getId()+ "and a.ticketid=b.ticketid and b.ticketblock= "+newticket.getTicketbolck()+ " ";
在a.ticketid= "+newticket.getId()+ "and a.ticketid=b.ticketid.
and前面要加个空格.否则就和前面的值连起来了,会报错的.
------解决方案--------------------楼上说的对,如果不容易看到的话,可以打印sql出来检查一下.比较直观.
------解决方案--------------------sqls= "SELECT price,ticketname,stock,sale FROM tickets as a,prices as b WHERE a.ticketid= ' "+newticket.getId()+ " ' and a.ticketid=b.ticketid and b.ticketblock= ' "+newticket.getTicketbolck()+ " ' ";
要加空格和 ' ' 这样写就没问题了。
------解决方案--------------------ticketblock为什么类型,如果为char或者varchar则要用下面的sql
sqls= "SELECT price,ticketname,stock,sale FROM tickets as a,prices as b WHERE a.ticketid= "+newticket.getId()+ "and a.ticketid=b.ticketid and b.ticketblock= ' "+newticket.getTicketbolck()+ " ' ";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~