JSP页面中 SQL 的写法!! 急!!!!!!!

shaoml 2007-11-15 01:52:55
我的两个表中已经有 存IP形式的字段varchar型的(58.24.0.0) 和转换后的字段bigint型的
在JSP页面中有两个变量 small和 big 是可以从另一个表中得到的(是IP转换后的bigint型)。rs.getLong( "small ") ....


我想 在页面中这样写个SQL语句
select count(*) from A where ip> small and ip <big (ip也是bigint型的)

SQL可以这样写吗?
...全文
155 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaoml 2007-11-16
  • 打赏
  • 举报
回复
已经解决,谢谢大家!

String sql="select count(*) from A where ip>'"+small+"' and ip<'"+big+"'";
xue08161981 2007-11-15
  • 打赏
  • 举报
回复
像这中sql 先在查询器上试下 或者打印出来 否则很难确定
erzhuanye 2007-11-15
  • 打赏
  • 举报
回复
写这里倒是可以,不过最好是处理的时候最好有统一的类。只是这种时候,变量和数据库对应连接上容易出问题
sunnykun 2007-11-15
  • 打赏
  • 举报
回复
可以把参数传到后台嘛,然后再拼装成一个合法的SQL。一般都是这样弄的
Janeweiz 2007-11-15
  • 打赏
  • 举报
回复
string sql="select count(*) from A where ip> '"+small+ "' and ip < '"+big+"'";
nanjg 2007-11-15
  • 打赏
  • 举报
回复
类似这样不确定的sql 先在查询器上试下 或者打印出来
shaoml 2007-11-15
  • 打赏
  • 举报
回复
另一个帖子。。。 http://topic.csdn.net/u/20071115/11/79f87a54-d63f-4367-aa35-b1505b43c796.html
awusoft 2007-11-15
  • 打赏
  • 举报
回复
"select count(*) from A where ip> "+small+" and ip <"+big;
shaoml 2007-11-15
  • 打赏
  • 举报
回复
写哪都无所谓,我的问题是那个SQL语句该怎么写?
String sql="select count(*) from A where ip>small and ip <big";
这个small和big值怎么在这句SQL中取到???
上善_若水 2007-11-15
  • 打赏
  • 举报
回复
理论上是可以的,不过要将变量和SQL先拼起来,
个人建议最好不要将SQL写在JSP页面上,养成好习惯,将java代码脱离JSP,更何况是连接数据库!
kbryant 2007-11-15
  • 打赏
  • 举报
回复
对阿,为什么要写在前台呢,写在JAVA程序里比较好
yiyexiao2003 2007-11-15
  • 打赏
  • 举报
回复
ip值可以这样比较吗?这个我没注意过的,不过你的这个最好不要写在jsp里面,写到java程序里面比较好的
tancy2008 2007-11-15
  • 打赏
  • 举报
回复
看不懂楼主是什么意思,不过那种写法一定是错的.
比较简单完整的jsp代码。如checklogin.jsp <%@ page import="java.sql.*" contentType="text/html;charset=GB2312" %> <% boolean success=true; boolean disable=false; String name=new String(request.getParameter("name").getBytes("ISO8859_1"),"GBK"); //将文字符转换成标准字符的写法 String password=new String(request.getParameter("password").getBytes("ISO8859_1"),"GBK");%> <%@ include file="conn.jsp"%> <% sql="select * from users where name='"+name+"' and password='"+password+"'"; ResultSet rs =statement.executeQuery(sql); if (rs.next()) { disable=rs.getBoolean("Disable"); if (disable) {success=false;} } else{ success=false; } %> <%@include file="disconn.jsp"%> <% if (success){ session.setAttribute("Name",name); // 思考:为什么用session 存放此变量,还有什么变量能存在session response.sendRedirect("list.jsp"); // 页面跳转 ,试试用另一种方式表现 }else if (disable){%> 该用户已经被禁用! <%}else{%> 用户名或密码有误,请重新登录! <%}%> 返回

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧