hello,
i am new to jsp and facing problem in creating a database entry from a jsp form where there will be a uid which will be auto incremented each time the form will be submitted. pls help me out with any kind of short code example so that i can understand easily.
Expecting reply at the earliest . . .
July 18, 2012 at 11:26 AM
Here is the code of inserting values from jsp form to database. In the database table, set the uid as the primary key and auto-increment. Then, whenever you submit the form,the values will get inserted along with the uid which is incremented automatically. There is no need to specify it in the query.
1)register.jsp:
<html>
<form method="post" action="insert.jsp">
<table>
<tr><td>First Name:</td><td><input type="text" name="fname"></td></tr>
<tr><td>Last Name:</td><td><input type="text" name="lname"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Confirm Password:</td><td><input type="password" name="cpass"></td></tr>
<tr><td>Date Of Birth</td><td><input type="text" name="dob"></td></tr>
<tr><td>Age:</td><td><input type="text" name="age"></td></tr>
<tr><td>Gender</td><td><input type="text" name="gender"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address"></td></tr>
<tr><td>Country</td><td><input type="text" name="country"></td></tr>
<tr><td>State:</td><td><input type="text" name="state"></td></tr>
<tr><td>City</td><td><input type="text" name="city"></td></tr>
<tr><td>Telephone No:</td><td><input type="text" name="tno"></td></tr>
<tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>
2)insert.jsp:
<%@page import="java.sql.*,java.util.*"%>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
String pass=request.getParameter("pass");
String cpass=request.getParameter("cpass");
String dob=request.getParameter("dob");
int age=Integer.parseInt(request.getParameter("age"));
String gender=request.getParameter("gender");
String address=request.getParameter("address");
String country=request.getParameter("country");
String state=request.getParameter("state");
String city=request.getParameter("city");
int telephone=Integer.parseInt(request.getParameter("tno"));
int mobile=Integer.parseInt(request.getParameter("mobile"));
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into student(firstname,lastname,email,pass,confirm_pass,dob,age,gender,address,country,state,city,telephone,mobile) values('"+fname+"','"+lname+"','"+email+"','"+pass+"','"+cpass+"','"+dob+"',"+age+",'"+gender+"','"+address+"','"+country+"','"+state+"','"+city+"',"+telephone+","+mobile+")");
out.println("Data is successfully inserted!");
}
catch(Exception e){
System.out.print(e);
e.printStackTrace();
}
Related Tutorials/Questions & Answers:
Mysql Alter Autoincrement; existing
table and add
autoincrement feature property to the
primary key...' definition
and add
autoincrement to the
primary key of the table 'employees...
Mysql Alter
Autoincrement
Advertisements
How to auto increment primary key in mysql...How to auto increment
primary key in
mysql... How to auto increment
primary key in
mysql...
and one more thing i need to get auto increment value in front end each time for
inserting the value[JSP
Mysql add primary key Mysql add
primary key
Mysql add
Primary Key is used to add
primary key on the column... of this tutorial illustrate an example from '
Mysql Add
Primary Key'. To understand
Mysql Alter Table Primary Key Mysql Alter Table
Primary Key
Mysql Alter Table
Primary Key is used to remove... an example from '
Mysql Alter Table
Primary
Key'. To understand this example, we create
Mysql Alter Column Primary Key Mysql Alter Column
Primary Key
Mysql Alter Column
Primary Key is used to modify table and redefine the
Primary Key Column in a table.
Understand with ExampleADS
Adding A Primary Key to an Existing Table a
primary key to a
MySQL table using Java for two days with no success. I'm new...("Error
inserting primary key");
}
I get the message: 'error
inserting primary key'.
Help, please and thank you
primary key and unique keyprimary key and unique key hello,
What's the difference between a
primary key and a unique
key?
hii,ADS_TO_REPLACE_1
Unique
key....
Primary key: columns entry of duplicate as well as null values are restricted
SQL Primary Key SQL
Primary Key
The
Primary Key in SQL is used to uniquely identifies each records in a
database table. The
Primary Key of the Table does not include NULL values
SQL PRIMARY KEY Constraint SQL
PRIMARY KEY Constraint
The
PRIMARY KEY constraint is used to uniquely identifies each
record in a
database table. The
Primary keys in a table contains
What is a "primary key"?What is a "
primary key"? What is a "
primary key"?
Hi,
Here is the answer,ADS_TO_REPLACE_1
A
primary key is used to uniquely identify...). A
primary key can consist of one or more fields on a table. When multiple fields
composinte primary key in hibernatecomposinte
primary key in hibernate I am facing following problem,
Inside the
database(mssql), i have created a table without
primary key...
primary key with all the columns of the table and hibernate s/w has created two pojo
difference between a primary key and a unique key?. But by default
primary key creates a clustered index(physical sorting of a
database table...difference between a
primary key and a unique
key? What's the difference between a
primary key and a unique
key?
Hi,
The column holding
changing primary key of parent tablechanging
primary key of parent table I want to change one
primary key from a table where
primary key is auto created? How can I do that? I have... to your
MySQL server version for the right syntax to use near 'upate person set
SQL PRIMARY KEY Constraint
SQL
PRIMARY KEY Constraint
The
PRIMARY KEY constraint is used to uniquely identifies each
record in a
database table. The
Primary keys in a table contains a unique
JDBC insert that returns primary keyJDBC insert that returns
primary key How to write code for jdbc insert that returns
primary key?
Help me fast
Thanks
Hi,
Following code can be used:
//Add record into
database
String queryInsert = "insert
Create primary key using hibernateCreate
primary key using hibernate How to create
primary key using hibernate?
The id element describes the
primary key for the persistent class and how the
key value is generated.
ADS_TO_REPLACE_1
SQL Alter Table Primary Key SQL Alter Table
Primary Key
Alter a Table
Primary Key in SQL modifies the existing table and adds a
primary key.
Create Table Stu_TableADS_TO_REPLACE_1
SQL
hibernate annotations with composite primary key to use hibernate annotations in case of composite
primary key in one table.
I tried like this, I have created a table without
primary key. By default mssql has created a composite
primary key with all the columns of the table.
table
php inserting date into mysqlphp
inserting date into mysql php
inserting date into
mysql
Here is a php code that inserts date into
mysql database. In the given code, data is a
database table.
<?php
table
$query_manual = "INSERT INTO data
Inserting values in MySQL database table Inserting values in
MySQL database table
... the facility
for
inserting the values in
MySQL database table.
Description...-mysql>java InsertValues
Inserting values in
Mysql database table
Inserting Data into mysql - SQL (using php)and
inserting the details in a
mysql database. Lets take for instance, a csv file named books and a
database table named books as well both...
Inserting Data into mysql My sincere apologize for this post. I
Define sequence generated primary key in hibernateDefine sequence generated
primary key in hibernate How to define sequence generated
primary key in hibernate?
Use value "sequence" for class attribute for generator tag.
<id column="USER_ID" name="id" type
SQL Auto increment Primary Key SQL Auto increment
Primary Key
SQL Auto increment
Primary Key is used to allow a unique... from 'SQL Auto increment
Primary Key'. To understand this example we use a query
SQL Alter Table Primary Key tutorial SQL Alter Table
Primary Key
Alter a Table
Primary Key in SQL modifies the existing table and adds a
primary key.
Create Table Stu_TableADS_TO_REPLACE_1
SQL
Foreign key in mysqlForeign
key in mysql Hi I am creating a website and linking it to a
database using php and
mysql. I need to create the databases in phpmyadmin... the foreign
key of one table into another table within phpmyadmin so the
database Mysql Alter Foreign Key Mysql Alter Foreign
Key
A Foreign
Key is a field that marks to the
primary key... illustrate an example from '
Mysql Alter Foreign
Key'. To
understand with example we
Inserting id in place of name to databaseInserting id in place of name to database Hello,
I have a
database department where I have "id" and "name". I am fetching this data to a jsp form in dropdown list displaying "name" there and Now I wanted to insert data from
Inserting data on a database in servlet - JSP-ServletInserting data on a
database in servlet Hi
I am following... to a databse by a servlet.I used the example in "
Inserting Data In
Database table...:8080/DataInsertion/DataInsertion) in the browser, I just saw my designed
database in the form
inserting an path of an image in database - JDBCinserting an path of an image in database hello
kindly help related... time its full path should be inserted in the
database(MS Sql 2000)..
I m able... be saved in the
database...I have tried it but getting an error..
plz have a look
urgent help for inserting database in a project urgent help for
inserting database in a project I need some urgent... and then the result at the end.I need to add simple
database connectivity... Southwindow(){
String []
key = {"","start:","next:","finish:","check next:","check
urgent help for inserting database in a project urgent help for
inserting database in a project I need some urgent... and then the result at the end.I need to add simple
database connectivity... Southwindow(){
String []
key = {"","start:","next:","finish:","check next:","check
problem on jsp, inserting data into table(mysql).problem on jsp,
inserting data into table(
mysql). hello friends, I have a problem in jsp.I want to insert data, which is given by user through a html page into a table.And the table name also is given by the user.My
database MYSQL DatabaseMYSQL Database Can any one brief me about how to use
MYSQL Database to store the create new
database, create tables.
Thanks.
Hi, the
MySQL database server is most popular
database server and if you want to know
alter table add foreign key mysqlalter table add foreign
key mysql Hi,
How to add foreign
key in
mysql using the query 'alter table add foreign
key mysql'
Thanks
Hi...,
Database MySQL MySQL Crash Tutorial Tutorial
Thanks
Setup MySQL DatabaseSetup
MySQL Database
... into
MySQL database. Table created here will be used in sample application.../mysql/mysql5/Installing-
MySQL-on-Windows.shtml
Creating
Database :
You can create