mahmoud
getting int values from form and insert it in data base in jsp
2 Answer(s)      4 years and 7 months ago
Posted in : JSP-Servlet

how can i get form input such as id convert it to int insert it into database

Advertisement
View Answers

December 26, 2010 at 7:35 PM


Hi,

You can get the parameter from the request object:

String s = request.getParameter("formfieldname");

Then convert it into Integer variable:

int i = Integer.parseInt(s);

Then you can write JDBC code to insert data into database.

Read JDBC Insert Statement Example for more detail.

Thanks



December 27, 2010 at 10:57 AM


Hi Friend,

Try the following code:

1)form.jsp:

<%@page import="java.sql.*"%>
<html>
<form method="post" action="insertdata.jsp">
<table>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Age:</td><td><input type="text" name="age"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)insertdata.jsp:

<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
int age=Integer.parseInt(request.getParameter("age"));
String address=request.getParameter("address");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age+",'"+address+"')");
         con.close();
         out.println("Data is successfully inserted into database.");
}
catch(Exception e){
    System.out.println(e);

}
         %>

Thanks










Related Tutorials/Questions & Answers:
getting int values from form and insert it in data base in jsp
getting int values from form and insert it in data base in jsp  how can i get form input such as id convert it to int insert it into database  ...=st.executeUpdate("insert into data(name,age, address) values('"+name+"',"+age
how to insert the bulk data into the data base from the table of jsp page to another jsp page
how to insert the bulk data into the data base from the table of jsp page... to insert the marks details into the data base i have retrive the rollno and name... to get values in array in next jsp page and insert into the row by row Please do
Advertisements
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
how to get a values from a multipart/form-data - JSP-Servlet
how to get a values from a multipart/form-data  Dear sir , I used your code for getting a values,i used the fllowing function... ,matter,file field values but not status and from field i am getting null
getting values from database - JSP-Servlet
getting values from database  I tried the following code abc.html aaa.jsp I am not getting exceptions now... JSP code separately.If it will not display database values then try your code
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
Retrieving data from data base using jsp combo box
Retrieving data from data base using jsp combo box  Hi guys please help me , i have on GUI page int that Server type(like apache,jboss,weblogic) one... of the server it has to display the process name from database into the process name
JSP data base validation
JSP data base validation  please explain how to validate form input string with database n also how its notify that entered data exists already... into student2(id, sName, phno) values(?,?,?)"; String sql2 = "select * from student2
data fecth from data base in( sql 2000) htmlform and jsp
data fecth from data base in( sql 2000) htmlform and jsp  hi iam using jsp and html form data fecth from database display the textbox help me i want whenever select from dropdown list select the projectname to display
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.
value is inserted into the sql table through jsp-jdbc but not getting stored into the data base,only row is increasing.  <html> <... ="INSERT INTO demodb VALUES('"+name+"','"+email+"','"+password
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp
data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp   data (image ,audio) inserting to data base (oracle 10g) and retriving the same data from jsp with script of data base plz help me
insert excel value in to oracle data base
insert excel value in to oracle data base  Hi All I am using... the data from the excel file using JDBC. For this you need to create dsn... org.apache.poi.hssf.usermodel.HSSFCell@19360e2 i am not getting right value... my code
How to insert data into databse by JSP form registration page in netbeans
How to insert data into databse by JSP form registration page in netbeans  ... of data for login purpose. I have created 1 form in JSP netbeans with both username...; password, & after submitting this form it automatically stores data
insert values - JSP-Servlet
insert values  How to insert values in the oracle database using JSP...;insert user_details values('"+username+"','"+jobposition+"... page<html><head><title>Insert value in database</title><
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form... values from one page to another consecutive page which is being called then we can
How to retrieve array values from html form to jsp?
How to retrieve array values from html form to jsp?  Hi! I am... it into jsp. Means i just want to retrieve values from html form containing array... sample code for how to retrive array values from html to jsp.   hi friend
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from... to the action. My action is getting called however, i am not sure how to pass
Displaying the values in text fields of a form from a javascript function in jsp
Displaying the values in text fields of a form from a javascript function... to call a javascript function by passing 3 values from applet. And i have to display these values in 3 text fields of a form in the current web page. Here form
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... to insert data from file. To understand this example, we create a table 'Stu_Table
for store data in data base - JSP-Servlet
.. and on 3rd form i use submit button... data of form 1 and 2 can also be store...for store data in data base  i want to a job site, in this site user can registered by a form.. in this form there are his information... i use
how to pass form values from javascript of html page to jsp page
how to pass form values from javascript of html page to jsp page   ... to submit all the form values with lattitude and longitude returned from showlocation funtion to submitform.jsp page and display latitude value in jsp page
Retrive the data from the table in data base using jdbc
Retrive the data from the table in data base using jdbc  Retrive the data from the table in data base using jdbc   JDBC Tutorials
Insert Data From File
Insert Data From File       Insert Data From File is  used to insert data from file... to insert data from file. To understand this example, we create a table 'Stu_Table
Getting data from servlet into javascript
Getting data from servlet into javascript  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
retrive data from data base and print it in every page until logout
retrive data from data base and print it in every page until logout  ... the USER NAME through retriving from database.suppose from home page he go to next... in JSP
FAILED TO INSERT DATA FROM FUNCTION();
FAILED TO INSERT DATA FROM FUNCTION();  HELLO, I HAVE A PROBLEM TO INSERT DATA FROM OUTPUT FROM FUNCTION()... I WANT TO STORE THE OUTPUT IN DATABASE... bigMac_ac1(){ $sql = "INSERT INTO fkpacademia (MAC) VALUES ('$row1['AVG(MAC
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown... data from database and display it on the textboxes. <%@page language="java
Wrong parameter values while exporting data from jsp to excel
Wrong parameter values while exporting data from jsp to excel   This is a jsp report. When i export the report data to an excel, the parameter values on the html report do not match those in the downloaded spreadsheet
Getting Textbox data from database
Getting Textbox data from database  When i m trying to get data in textbox as readonly from database i m getting following error.and my code is shown...;Here is a jsp code that retrieves data from database and display
insert values from excel file into database
insert values from excel file into database   hi i want to insert values from Excel file into database.Whatever field and contents are there in excel... the following link: Insert values from excel file to database
data base
data base  how to connect coding in data base ?   The given code connects JSP page to database. You need to import the mysql connection jar file to jdk as well as to the lib of tomcat. Moreover you need to set classpath