java - MySQL and JSP Database connectivity with Glassfish server 4 -
here code.
**insert.html** <html> <head> <title>donate blood !</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <form action="store.jsp" method="post"> name: <input type="text" name="nam"><br> rollno: <input type="text" name="rno"><br> blood group: <input type="text" name="grp"><br> <input type="submit" value="add me !"> </form> </body> </html> **store.jsp** <%@page import="java.sql.drivermanager"%> <%@page import="java.sql.statement"%> <%@page import="java.sql.connection"%> <% string name = request.getparameter("nam"); string roll = request.getparameter("rno"); string group = request.getparameter("grp"); class.forname("com.mysql.jdbc.driver").newinstance(); connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/blood","root",""); statement st = con.createstatement(); int i=st.executeupdate("insert blood(name,rollno,bloodgroup) values('+name+','+roll+','+group+')"); %>
my database..
i running code in netbeans 8.0. got error log
it shows data long blood group given 'a+' in textbox. whats going wrong. new jsp please me. in advance.
try using preparedstatement instead avoid string concatenation mistakes.
preparedstatement st = con.preparestatement("insert blood(name,rollno,bloodgroup) values(?,?,?)"); st.setstring(1, name); st.setstring(2, roll); st.setstring(3, group); st.executeupdate();
Comments
Post a Comment