2013-04-05 62 views
0

請解決更新查詢的查詢問題(使用JSP)更新使用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 

回答

0

似乎沒有問題與語法,應該工作。

實施例:

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秒)