【问题标题】:update query issue using jsp使用jsp更新查询问题
【发布时间】:2013-03-27 11:14:48
【问题描述】:

请解决更新查询(使用jsp)

//resultset 是 ResultSet 对象并正常工作 //rsmd 是 ResultSetMetaData 对象 & 正确获取数据

    for(int i=1;resultset.next();i++)
    {
    update_query="UPDATE DEMO_TABLE SET ";

    for(int j=1;j<=rsmd.getColumnCount();j++)
    {
        temp_str=request.getParameter(rsmd.getColumnName(j)+i);     // i am having id of textboxes as of columnname1,columnname2(eg. S_NO1, NAME1) using this

        if(j==rsmd.getColumnCount())
        {
           update_query+=rsmd.getColumnName(j)+"=\'"+temp_str+"\'" ;//not working
//WORKING  update_query+=rsmd.getColumnName(j)+"=\""+ temp_str+"\""  ;
        }

        else
        {
           update_query+=rsmd.getColumnName(j)+ "=\'"+ temp_str+"\' ,";//not working
//WORKING  update_query+=rsmd.getColumnName(j)+ "=\"" + temp_str + "\" ,";
        }
    }

.
.
.
.
remaining update query statement with where clause...

please help...it's not working i.e. it's not inserting single quotes in update_query string

【问题讨论】:

    标签: database jsp sql-update resultset


    【解决方案1】:

    语法似乎没有问题,应该可以。

    例子:

    public static void main(String[] arg) {
            String strColName="empName";
            String strVal = "smith";
            String update_query = "Update employee SET "; 
            update_query += strColName + "=\'"+ strVal +"\'"; 
            System.out.println(update_query);
        }
    

    输出:

    运行:

    更新员工 SET empName='smith'

    构建成功(总时间:0 秒)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      相关资源
      最近更新 更多