Hi, I am taking some value from a html form which has one text area filed and inserting this value into the table along some other values. I am using this in servlets and the value is getting from request.getParameter("test"); When i am trying to insert the following value into the text field of a table, the value is changing and the new one is inserting in the table. I tried both preparedStatement and Statement object for insertion.. Mysql version 3.23.36 Input: This is giving in textarea of html code.... main() { fprintf("hi"); } when i am inserting into database it is inserting as main() fprintf("hi"); {} --- why it is like this........ My code: html code: <html> <head> <title>Untitled</title> </head> <body> <FORM action=/servlet/test2 method=post name=t> <TABLE> <TR> <TD> <P align=center>Enter value</P></TD> <TD><TEXTAREA cols=25 name=desc rows=5></TEXTAREA></TD></TR> <TR> <TD><INPUT name=s type=submit value=submit></TD> <TD><INPUT type=reset value=Reset></TD></TR></TABLE> </FORM> </body> </html> SERVLET CODE: import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import com.wipro.sspkm.connection; public class test2 extends HttpServlet { Connection con = null; public void init(ServletConfig config) throws ServletException { super.init(config); // establish connectin with database. try { con = connection.getConnection(); } catch(ClassNotFoundException e) { System.out.println("Database driver - SQLException" + e.getMessage()); } catch(SQLException e) { System.out.println("Connection and statement - SQLException" + e.getMessage()); } catch(Exception e) { System.out.println("Connection and statement - Other Exception" + e.getMessage()); } } // init public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); try { String desc = req.getParameter("desc"); int upd =0; /* // Using Statement Statement st= con.createStatement(); upd = st.executeUpdate("insert into test values('"+desc+"')"); */ // Using preparedStatement PreparedStatement pst = con.prepareStatement("insert into test values(?)"); pst.setString(1,desc); upd = pst.executeUpdate(); if (upd != 0 ) out.println("inserted the row with value"); else out.println("not inserted"); }catch(SQLException e) { System.out.println("sqlexception "+e); } catch(Exception e) { System.out.println("sqlexception "+e); } } } Hope will get the answer ....... -venkatesh
The Information contained and transmitted by this E-MAIL is proprietary to Wipro Limited and is intended for use only by the individual or entity to which it is addressed, and may contain information that is privileged, confidential or exempt from disclosure under applicable law. If this is a forwarded message, the content of this E-MAIL may not have been sent with the authority of the Company. If you are not the intended recipient, an agent of the intended recipient or a person responsible for delivering the information to the named recipient, you are notified that any use, distribution, transmission, printing, copying or dissemination of this information in any way or in any manner is strictly prohibited. If you have received this communication in error, please delete this mail & notify us immediately at [EMAIL PROTECTED]
--------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php