Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet inserting into mysql database with uid to be primary key and autoincrement

Have Programming Question? Ask it here!
 
 
 


Romil Roy
inserting into mysql database with uid to be primary key and autoincrement
1 Answer(s)      2 years ago
Posted in : JSP-Servlet


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 . . .


Advertisement
View Answers

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:
inserting into mysql database with uid to be primary key and autoincrement
inserting into mysql database with uid to be primary key and autoincrement ...; 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
Mysql Alter Autoincrement
; existing table and add autoincrement feature property to the primary key... 'employees' definition and add autoincrement to the primary key of the table... 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
Difference between not null and primary key in mysql
Difference between not null and primary key in mysql  Explain not null and primary key in mysql
Mysql Alter Table Primary Key
Mysql Alter Table Primary Key       Mysql Alter Table Primary Key is used to remove the primary key from the table and add primary key to the existing other column of table
Mysql Alter Column Primary Key
Mysql Alter Column Primary Key       Mysql Alter Column Primary Key is used to modify table... The Tutorial illustrate an example from 'Mysql Alter Column Primary Key
primary key and unique key
primary key and unique key  Whats is mean by primary key and unique key
primary key and unique key
primary key and unique key  hello, What's the difference between a primary key and a unique key?   hii, Unique key: column restricts entry of duplicate values but entry of null values is allowed. Primary key
Data is not inserting correctly in mysql database.
Data is not inserting correctly in mysql database.  Hello Sir, below is my code to insert data into database by list iteration...( "jdbc:mysql://localhost:3306/asteriskcdrdb", "root", "techsoft
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
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 a unique
What is a "primary key"?
What is a "primary key"?  What is a "primary key"?   Hi, Here is the answer, A primary key is used to uniquely identify each row... be an artificial field (one that has nothing to do with the actual record). A primary key can
composinte primary key in hibernate
composinte 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?
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 the primary key constraint cannot accept null values.whereas column holding
changing primary key of parent table
changing 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 key
JDBC 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 hibernate
Create 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.   <id name="id
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_Table SQL statement to create
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
how tohow to create a table with primary key and foreign keyhow to create a table with primary key and foreign key
how tohow to create a table with primary key and foreign keyhow to create a table with primary key and foreign key  how to create a table using java language with primary key and foreign key   Hi Friend, A foreign
inserting image in mysql database using browse button in servlets
inserting image in mysql database using browse button in servlets  Hi,I want to insert a image in mysql database using browse button. and, i want... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); File f = new File
How to create primary key using hibernate?
How to create primary key using hibernate?  Hi, How to create primary key using hibernate? Thanks
php inserting date into mysql
php 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
query regarding auto increment primary key
query regarding auto increment primary key  i want to use s1,s2.... as my auto increment primary key.cant i do this in mysql
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 hibernate
Define 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
Inserting values in MySQL database table
Inserting values in MySQL database table   ... the facility for inserting the values in MySQL database table. Description... insert values in the MySQL database table. We know that tables store data in rows
inserting image into database
inserting image into database  how to insert image into database using struts frame work and spring JDBC
SQL Auto increment Primary Key
SQL Auto increment Primary Key       SQL Auto increment Primary Key is used to allow a unique... increment Primary Key'. To understand this example we use a query 'use
inserting multiple file formats into database
inserting multiple file formats into database  hi i want to insert multiple file format like .pdf.doc.zip into mysql database using jsp
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_Table SQL statement to create
can we update table in hibernate with out primary key in table?
can we update table in hibernate with out primary key in table?  can we update table in hibernate with out primary key in table
Mysql Alter Foreign Key
Mysql Alter Foreign Key       A Foreign Key is a field that marks to the primary key... from 'Mysql Alter Foreign Key'. To understand with example we create a table
Foreign key in mysql
Foreign 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
inserting dropdown values into database table
inserting dropdown values into database table   hi i want to insert dropdown values into a database table by using jsp
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
inserting an path of an image in database - JDBC
inserting 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
Inserting data on a database in servlet - JSP-Servlet
Inserting 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
Identify correct and incorrect statements or examples about an entity bean's primary key and object identity.
by the underlying database system that stores the entity objects. The primary key... an entity bean's primary key and object identity. Prev Chapter 8... and incorrect statements or examples about an entity bean's primary key and object
Mysql Alter Unique Key
Mysql Alter Unique Key     ... with Example The Tutorial illustrate an example from 'Mysql Alter Unique Key... respectively. The table has a ID as Primary Key.  Create table "
alter table add foreign key mysql
alter 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
inserting multiple file formats into database using html
inserting multiple file formats into database using html   hi the code was working fine,i want to choose the file and then upload to database,by using html.whether it is possible to upload larger file size,please explain
Inserting values into a database table of selected DropDown in jsp.
Inserting values into a database table of selected DropDown in jsp.  http://www.roseindia.net/answers/viewqa/Ajax/15250-DropDown-in-ajax+jsp.html Thank you for this program, it helped me alot to learn. I have done it. now i want
Inserting Image in Database Table
Inserting Image in Database Table   ... to the MySQL database table.  Flow of the process : This program helps the user to insert an image in the MySQL database table. To insert
Lock while inserting/updating database in multithreaded.
Lock while inserting/updating database in multithreaded.  Hi, I am... inserting/updating to database. I dont know what is the issue but it was never... site but its coming at deployment site only. I verified all database indexes. I
Advertisements
 

 

 

DMCA.com