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



Home Answers Viewqa JDBC select maximum from table and hoe to store it in any variable

Have Programming Question? Ask it here!
 
 
 


shiv vaishnav
select maximum from table and hoe to store it in any variable
2 Answer(s)      3 years ago
Posted in : JDBC


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


Advertisement
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
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? Please clarify this. Thanks
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
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
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... keyword in SQL is used to show the records from table 'Stu'. select
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. Thanks
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
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
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
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
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
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
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
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
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
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
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">
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
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 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
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
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
MySQL Select Statement
clause. The SELECT statement is used to retrieve the records from the table... of Emp table. mysql> SELECT * FROM Emp; If you want... fields from the Emp table. mysql> SELECT Name, City, Age from EMP
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
send multiple textbox vaues in to an jsp form to store them in a DB table
values in to an jsp file with additional values to store those values in to an database table. Please help me...... looking forward to hear from you...send multiple textbox vaues in to an jsp form to store them in a DB table 
Getting environment variable value from java
Getting environment variable value from java  Getting environment variable value from java
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
how to store data in other table using servlet and jsp
how to store data in other table using servlet and jsp  pls can anyone tell how to store data in other table using servlet and jsp and want to display that data too.and the data in first table must be same.pls help
Hibernate Select Clause
from Insurance table using Hibernate Select Clause. The select clause picks up..., insurance.investementDate) from Insurance table. Hibernate generates the necessary sql query and selects all the records from Insurance table. Here
store & retrive the image from oracle database
store & retrive the image from oracle database  how can i store the image path in tha database & fetch that image from oracle database
JDBC Select Statement Example
= con.createStatement(); // creating Query String String query = "SELECT * FROM... .style1 { text-align: center; } JDBC Select Statement Example Select Statement retieves the data from single or multiple tables from a database
how to store and retrieve image from database
how to store and retrieve image from database  how to store and retrieve images into database(oracle) and how to retrive images from database using...(); ResultSet rs=st.executeQuery("select images from image"); if(rs.last()){ byte
how to store data in table using swings - Java Beginners
how to store data in table using swings  Hi, I am doing a project in which i need to store some data in the table using swings.......Iam using... will be same to store data into tables) of my application....can any body give an example
Mysql From Table
Mysql From Table       Mysql From Table is used to specify the table from which the records... for From The keyword 'from' is used to specify the table 'Stu' from which records
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
store and retrive image from database - JDBC
store and retrive image from database  how to store and retrive an image in database using java?  Hi friend, Code for store image...()); } } } For retrieve image from database visit to : http
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...(); String sql = "SELECT * FROM employeedetails"; resultSet
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
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"
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
Jsp-delete checked checkboxes and display UNCHECKED checkboxes in table as well as in store that unchecked checkboxes in ARRAYLIST
as in store that unchecked checkboxes in ARRAYLIST  I have a table... are to be deleted from the table after clicking the DELETE button. If this is your... values from the table. Use form tag and checkbox input. In in each checkbox
PHP SQL Select Where
; PHP SQL Select Where is used to provide the records from the table... from 'PHP SQL Select Where'. To understand and grasp the example we create a table user. The select Query is used to return the records from table 'user'. 
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
add text box and select list dynamically and get its value to store it into database using jsp request parameter
add text box and select list dynamically and get its value to store it into database using jsp request parameter  its very helpful when you have only... added select box also into next jsp page plz reply me as early as posssible
how can i store text box values as it is in database table
how can i store text box values as it is in database table  CUSTOMER DESCRIPTION
Advertisements
 

 

 

DMCA.com