Topic: 求助(谢谢)(SELECT ... WHERE 字段 = 变量 怎么写)

  Print this page

1.求助(谢谢)(SELECT ... WHERE 字段 = 变量 怎么写) Copy to clipboard
Posted by: YoYo
Posted on: 2004-08-13 10:14

jsp程序中,用select查询数据库,where子句让一个字段的名字等于一个变量改怎么写
-------谢谢


{ 请尽量用准确的文字描述作为标题

0. you should be able to find the answer from any book/article about JSP/SQL.

1. sqlText = "select field1, ..., fieldn from tablename where fieldx =" + properlyFormattedVariable
(not recommended)

2. use preparedStatement
PreparedStatement preparedStatement = connection.prepareStatement(
"select field1, ..., fieldn from tablename where fieldx = ?" );
prepareUpdatePrice.setInt(1, intVariable);
// prepareUpdatePrice.setString(1, stringVariable);
// ...

... if possible, don't use Select *

-- why }

2.Re:求助(谢谢) [Re: YoYo] Copy to clipboard
Posted by: flymandl
Posted on: 2004-08-13 11:31

可以使用java.sql.PreparedStatement的某个实现,一般是这个样子
select * from aTable Where aColumnNmae = ?

然后在后面的语句中把参数设进去。

不过不管多小的项目,还是尽量不要直接在jsp中写上sql语句好一些。

3.Re:求助(谢谢)(SELECT ... WHERE 字段 = 变量 怎么写) [Re: YoYo] Copy to clipboard
Posted by: YoYo
Posted on: 2004-08-14 08:40

谢谢

4.Re:求助(谢谢)(SELECT ... WHERE 字段 = 变量 怎么写) [Re: YoYo] Copy to clipboard
Posted by: marsboy
Posted on: 2004-08-19 23:01

select * from table where columnname="+colum+"
你试一下吧!!


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923