select maximum from table and hoe to store it in any variable

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:
select maximum from table and hoe to store it in any variable
select maximum from table and hoe to store it in any variable  public..."); } } } i want to select max(sn) from table then insert into table...+"','"+s+"')"); ResultSet rs=st.executeQuery("select * from detail"); //" &
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
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir... to store that data in int variable. how to do this ?   Here is an example...=conn.createStatement(); ResultSet rs=st.executeQuery("select * from numbers
mysql select into table from another table example
mysql 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 dynamically
Hoe 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 - JDBC
Table 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 - JDBC
select 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 Java
Store 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
What?s the maximum size of a row in SQL table?
What?s the maximum size of a row in SQL table?  What?s the maximum size of a row in SQL table?   Hi, The maximum Row Size is 8060 Bytes in a sql table.ADS_TO_REPLACE_1 Thanks
How to display all the Select values from the MySQL database table in where condition= In JSP?
How to display all the Select values from the MySQL database table in where... to display all the select values from MySQL DB** only first value is displayed in the jsp file. @select * from table dept where dept_no=10;" jsp code i have used
Select from select list + display
Select 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
I want to store the value of local variable into Global variable
I want to store the value of local variable into Global variable    <%=cnt%>=x; is it a valid Statement
Extracting variable from jsp
Extracting 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
SQL select statement doesn't return any rows,
SQL select statement doesn't return any rows,  When an SQL select statement doesn't return any rows, is an SQLException thrown
declare a variable that will store an array of 5 objects
declare a variable that will store an array of 5 objects  Q7. Give a declaration for a variable that will 'store' an array of 5 Card objects. this is my segment: list = new int[5]; I don't know if it is right or wrong. So
how I do select from select in hql
how 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
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I am getting the data's from the table that was stored in database. Now in the page in which i am getting all the data from the database has an another select
how to select the row value that was retrived from the database ?
how to select the row value that was retrived from the database ?  I am getting the data's from the table that was stored in database. Now in the page in which i am getting all the data from the database has an another select
update one table from another table
update 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
retrieve value from database on the basis of maximum id number
retrieve value from database on the basis of maximum id number  hi, i want to retrieve value of maximum id number from the database and show that value in jTextField.when the user clicks on the button that maximum id number
Select data from diplicated data
Select 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
ModuleNotFoundError: No module named 'django-table-select-widget'
ModuleNotFoundError: No module named 'django-table-select-widget'  Hi...: No module named 'django-table-select-widget' How to remove the ModuleNotFoundError: No module named 'django-table-select-widget' error? Thanks
ModuleNotFoundError: No module named 'django-table-select-widget'
ModuleNotFoundError: No module named 'django-table-select-widget'  Hi...: No module named 'django-table-select-widget' How to remove the ModuleNotFoundError: No module named 'django-table-select-widget' error? Thanks
ModuleNotFoundError: No module named 'django-table-select-widget'
ModuleNotFoundError: No module named 'django-table-select-widget'  Hi...: No module named 'django-table-select-widget' How to remove the ModuleNotFoundError: No module named 'django-table-select-widget' error? Thanks
ModuleNotFoundError: No module named 'django-table-select-widget'
ModuleNotFoundError: No module named 'django-table-select-widget'  Hi...: No module named 'django-table-select-widget' How to remove the ModuleNotFoundError: No module named 'django-table-select-widget' error? Thanks
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
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
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 document
Extracting 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 database
store 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 gridview
store 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 c
Select 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 table
retrieve 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
How many cookie object we can store in a session? is there any limit?
How many cookie object we can store in a session? is there any limit?  How many cookie object we can store in a session? is there any limit
Getting Json data from servlet to javascript variable
Getting Json data from servlet to javascript variable  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
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"
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
Total summay from a sale table
Total summay from a sale table  Total summay from a sale table
unable to get value returned from javascript variable in page
unable to get value returned from javascript variable in page  Hi, I... jsp page..what i want is to store the value returned from the js function and store it in a variable so that i can use it in my servlet to validate an if else
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 map
read 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 database
Select 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

Ads