Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code block to get the updated values

XML
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h3>Updated Successfuly!!</h3>

       <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306/mysql"
     user="root"  password="root"/>

        <sql:update dataSource="${snapshot}" var="result">
            UPDATE user_reg_ml SET  uname=${param.uname} ,email=${param.email} ,country=${param.country} where id=${param.id}
        </sql:update>
    <%--
        <sql:query var="result" dataSource="${snapshot}">
            select * from user_reg_ml where id=${param.id}
        </sql:query>
         <table>

        <c:forEach var="row" items="${res.rows}">
            <tr>
                <td>
                    ID
                </td>
                 <td>
                    ${row.id}
                </td>
            </tr>
            <tr>
                <td>
                    Name
                </td>
                <td>

                    ${row.uname}
                </td>
            </tr>
            <tr>
                <td>
                    Email
                </td>
                <td>
                    ${row.email}
                </td>
            </tr>
            <tr>
                <td>
                    Country
                </td>
                <td>
                    ${row.country}
                </td>
            </tr>
        </c:forEach>
    </table>
    --%>
    </body>
</html>




and this is my code block to edit values

XML
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        Welcome ${uname}

     <form action="update_mypage.jsp" method="post">

<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
     url="jdbc:mysql://localhost:3306/mysql"
     user="root"  password="root"/>

<sql:query dataSource="${snapshot}" var="result">
select * from user_reg_ml where uname='${param.uname}' and pwd='${param.pwd}'
</sql:query>
        <%--input type="hidden" name="user" value="${param.uname}"--%>

        <c:forEach var="row" items="${result.rows}">
            ID: <input type="text" name="id" value="${row.id}" ><br/>

            USERNAME:  <input type="text" name="uname" value="${row.uname}"><br/>

            EMAIL: <input type="text" name="email" value="${row.email}"><br/>

            COUNTRY: <input type="text" name="country" value="${row.country}"><br/>

        </c:forEach>

        <input type="submit" value="update">
</form>

    </body>
</html>



but when i click update button, i get following error

HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception
javax.servlet.ServletException:
UPDATE user_reg_ml SET uname=abc ,email=abc@gmail.com ,country=India where id=1
: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com ,country=India where id=1' at line 1


root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com ,country=India where id=1' at line 1


note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.
Posted
Comments
Richard MacCutchan 12-Aug-15 10:09am    
What does the documentation say about strings containing the '@' sign?
Member 9671810 12-Aug-15 10:30am    
i have error if i pass only uname also.

It is likely that your email string needs to be quoted, like:
SQL
UPDATE user_reg_ml SET  uname=${param.uname}, email='${param.email}', country=${param.country} where id=${param.id}

I also suggest putting your space-comma sequences the other way round as I have. Probably makes no difference but it certinly looks more correct.
 
Share this answer
 
Comments
Member 9671810 12-Aug-15 10:29am    
again i have the same error

javax.servlet.ServletException:
UPDATE user_reg_ml SET uname=abc ,email=abc@gmail.com ,country=India where id=1UPDATE user_reg_ml SET uname=abc, email='abc@gmail.com', country=India where id=1
: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gmail.com ,country=India where id=1UPDATE user_reg_ml SET uname=abc, email=' at line 1
Richard MacCutchan 12-Aug-15 10:37am    
Look at that statement. What do you expect?
Member 9671810 12-Aug-15 10:42am    
but do you think there is any syntax error?? infact i tried to update maually using uname=abc. then also there is an error saying unknown column in fieldlist.
Richard MacCutchan 12-Aug-15 10:49am    
OK, so what are the column names supposed to be?
Member 9671810 12-Aug-15 10:55am    
same as what i passed, id,pwd,uname,email and country
SQL
<sql:update dataSource="${snapshot}" var="result">
           update user_reg_ml SET  uname="${param.uname}" ,email="${param.email}" ,country="${param.country}" where id='${param.id}'
       </sql:update>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900