select maximum from table and hoe to store it in any variable
public class signup extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String u=request.getParameter("user");
String p=request.getParameter("password");
String c=request.getParameter("city");
String m=request.getParameter("mobile");
String s=request.getParameter("salary");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:student");
Statement st=cn.createStatement();
ResultSet i=st.executeQuery("select MAX(sn) from detail");
int x=i.getInt(1);
x=x+1;
st.executeUpdate("insert into detail values(3,'"+u+"','"+p+"','"+c+"','"+m+"','"+s+"')");
ResultSet rs=st.executeQuery("select * from detail"); //" & ' me space ni dena h
while(rs.next()){
out.println("login success"+"<br>");
out.println("ur details are:<br>");
out.println("user name : "+rs.getString(2)+"<br>");
out.println("city : "+rs.getString(4)+"<br>");
out.println("mobile : "+rs.getString(5)+"<br>");
out.println("salary : "+rs.getString(6)+"<br>");
}
cn.close();
}
catch(ClassNotFoundException e){
out.print("class not found");
}
catch(SQLException e){
out.print("sql error");
}
}
}
i want to select max(sn) from table then insert into table as(max+1,user,password,city,mobile,salary)..
help me pls
View Answers
July 13, 2011 at 2:52 PM
Try this:
public class signup extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String u=request.getParameter("user");
String p=request.getParameter("password");
String c=request.getParameter("city");
String m=request.getParameter("mobile");
String s=request.getParameter("salary");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:student");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select MAX(sn) from detail");
int x=0;
while(rs.next()){
x=rs.getInt(1);
}
int y=x+1;
st.executeUpdate("insert into detail values("+y+",'"+u+"','"+p+"','"+c+"','"+m+"','"+s+"')");
ResultSet rst=st.executeQuery("select * from detail");
if(rst.last()){
out.println("login success"+"<br>");
out.println("ur details are:<br>");
out.println("user name : "+rst.getString(2)+"<br>");
out.println("city : "+rst.getString(4)+"<br>");
out.println("mobile : "+rst.getString(5)+"<br>");
out.println("salary : "+rst.getString(6)+"<br>");
}
cn.close();
}
catch(ClassNotFoundException e){
out.print("class not found");
}
catch(SQLException e){
out.print("sql error");
}
}
}
July 13, 2011 at 2:52 PM
Try this:
public class signup extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String u=request.getParameter("user");
String p=request.getParameter("password");
String c=request.getParameter("city");
String m=request.getParameter("mobile");
String s=request.getParameter("salary");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:student");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select MAX(sn) from detail");
int x=0;
while(rs.next()){
x=rs.getInt(1);
}
int y=x+1;
st.executeUpdate("insert into detail values("+y+",'"+u+"','"+p+"','"+c+"','"+m+"','"+s+"')");
ResultSet rst=st.executeQuery("select * from detail");
if(rst.last()){
out.println("login success"+"<br>");
out.println("ur details are:<br>");
out.println("user name : "+rst.getString(2)+"<br>");
out.println("city : "+rst.getString(4)+"<br>");
out.println("mobile : "+rst.getString(5)+"<br>");
out.println("salary : "+rst.getString(6)+"<br>");
}
cn.close();
}
catch(ClassNotFoundException e){
out.print("class not found");
}
catch(SQLException e){
out.print("sql error");
}
}
}
Related Tutorials/Questions & Answers:
store data from a variable in mysql?store data
from a
variable in mysql? sir
last time asked you tell me how to retrieve data
from a database mysql and
store it in an int
variable... of the calculation
from an int
variable into mysql in a new
table of database. how
Advertisements
mysql select into table from another table examplemysql
select into
table from another
table example Can you suggest the correct example of
select into
table from another
table example in MySQL...
from one
table into another
table.
Check the example at MySQLselect into new
Hoe to refresh a table row dynamicallyHoe to refresh a
table row dynamically Want to refresh a
table data... Friend,
Is there a link attribute with every row of a
table through which we will able to refresh a particular
table row?ADS_TO_REPLACE_1
Please clarify
Table maximum Row count - JDBCTable maximum Row count Dear friends
I want to
select maximum time entry Status
from db.
for example :
Status : 3 4 6 8 3 5 7 5...,
Sql Query for
select maximum value max() function use.
"
select max
Select data from Table in Database Select data
from Table in Database
... the selected data
from table in database. The
select query in the database retrieve...; in simple
select statement is given
below
select column name
from table;ADS
select maximum time entry row - JDBCselect maximum time entry row Hi fried
you given ans this
Sql Query for
select maximum value max() function use.
"
select max(fieldname... is
maximum time entry in column Status
please if you have
any other query
Store Variable in JavaStore Variable in Java How to
store Variables in Java?
public class DoubleTest {
public static void main(String[] args) {
double...(aDouble); // Outputs 7.21
}
}
Variable in Java
SQL Select From
SQL
Select From
SQL
Select From keyword show you the records
from a specified
table.
Understand... the records
from table 'Stu'.ADS_TO_REPLACE_4
select *
from Stu
Select from select list + displaySelect from select list + display i have a
select list containing...
select EmpCode
from the
select list,
the corresponding EmpName and DeptName should...=con.createStatement();
ResultSet rs=st.executeQuery("
select *
from emp
Extracting variable from jspExtracting
variable from jsp how to Write a java program which will be extracting the variables and putting them in an excel format?
The given code allow the user to enter some fields and using the POI API
how I do select from select in hqlhow I do
select from select in hql
select RN
from (
select rownum RN, dbid
from (
select *
from profile p where type = 1912 and name like... doesn't work
select RN
from (
select rownum RN, DBId
from (
select distinct p
update one table from another tableupdate one
table from another table hello, i need to update one.... for example TotalQuantity field
from Products
table should be updated if i... *
from (
select sum(products.totalquantity)+sum(productspurchased.quantity)
from Select data from diplicated dataSelect data
from diplicated data hello i have
table
location...++)
{
$SQL = "
SELECT duration
FROM core_network WHERE location=('".$location_c[$k... = mysql_
select_db($database, $db_handle);
if ($db_found) {
$SQL = "
SELECT mysql select from multiple tables mysql
select from multiple tables how can i
select the date field
from multiple tables in mysql?
"UNION" can be used to
select data
from multiple tables in my sql...
for example
(
SELECT *
from name where `name
Using Select Statements in JDBC;
The
SELECT statement is used to
select data
from a
table. For terminating a statement,
semicolon is used.
When we want to fetch the data
from any table... to retrieve the data
from any table with the
JDBC. Employee is the name of a
table Mysql From Table
Mysql
From Table
Mysql
From Table is used to specify the
table from which the records...
from 'Mysql
From Table'. To grasp
this example we create a
table 'Stu
Extracting equation from any documentExtracting equation
from any document how can i extract equation
from any word document?
Hello Friend,
If you want to extract data
from the word file, then visit the following link:
Extract data
from word document
store and retrive image from the databasestore and retrive image
from the database please provide me... to
store and retreive images
from sql database using sql commands
-how to
store and retreive images
from sql database using asp.net/c#
thanks in advance
MySQL Select Statement clause. The
SELECT statement is used to retrieve the records
from the
table... of Emp
table.
ADS_TO_REPLACE_1
mysql>
SELECT *
FROM Emp...,
City and Age fields
from the Emp
table.
mysql>
SELECT Name, City
store value in checkbox from gridviewstore value in checkbox
from gridview Please check the error... = con.createStatement();
rst=st.executeQuery("
select *
from books...;
<
table bgcolor="pink" border="1" cellspacing="0" cellpadding="0">
JDBC Select Statement Example
String query = "
SELECT *
FROM student";
// excecuting query
rs...
.style1 {
text-align: center;
}
JDBC
Select Statement Example
Select Statement retieves the data
from single or multiple tables
from a
database
Select string from array in objective cSelect string
from array in objective c Hi, I wanted to
select a string
from the database
table in objective c. But somehow it is not working..can...:@"
SELECT ic, district, age, race, referralSource, DMRelatedAdmin, postalCode
FROM retrieve record from tableretrieve record
from table Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data
from the field
table. Actually
Hibernate Select Clause from Insurance
table using Hibernate
Select Clause. The
select clause
picks up..., insurance.investementAmount, insurance.investementDate)
from Insurance
table.
Hibernate...
table. Here is the code of our java file which
shows how
select HQL can be used
select result from three tables using sql.select result
from three tables using sql. I want to get a result
from three tables. i dont how to write the sql query. Please help me.
"I want to display Name,Username and Product_Name where Id=007"
table "register"
Name
Select query in JSP that we use
SELECT query.
SELECT query is a retrieve the data
from database than... interface.
Syntax of
select query:-
SELECT *
FROM TableName;
Now we have... = connection.createStatement();
String sql = "
SELECT *
FROM employeedetails"
JDBC Select All Records Example records
from the
table use mysql
JDBC driver. This tutorial example for select all records
from table
if exist and defined how the records fetch and
store.
This example applied mysql query "
SELECT *
FROM user"
How you will Show all data from a table. How you will Show all data
from a
table. How you will Show all data
from a
table.
Hi,
following query is used to show all the data of the
table-ADS_TO_REPLACE_1
SELECT *
FROM tablename;
Thanks
read from file and store using hash mapread
from file and
store using hash map I was stuck with a java project where I have to read a file with two different concepts and
store them... different maps.
Any help will be appreciated. Thanks in advance
Select tag to fetch data from oracle databaseSelect tag to fetch data
from oracle database I created a
select box having more than one menus in the
select box such as regnno, address and name of a student and when regnno is selected
from the drop down list by a user