Share on Google+Share on Google+

D Student
JDBC and Aggregate values
1 Answer(s)      6 years and 2 months ago
Posted in : JDBC

How to get the aggregate value using JDBC?

Like I am executing the statement "Select Max(ItemId) from Items", and I get only one row, only one column in return and I want to get that data using JDBC. How may I do it?

Ads

View Answers

February 22, 2011 at 12:49 PM


Java JDBC retrieve selected value

import java.sql.*;
class Get 
{
    public static void main(String[] args) throws Exception
    {
        Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("Select Max(id) from items");
            int id=0;
               if(rs.next()){
                    id=rs.getInt("Max(id)");

               }
               System.out.println(id);
               ResultSet rs1=st.executeQuery("Select * from items where id="+id+"");
                   while(rs1.next()){
                       System.out.println(rs1.getString(1)+" "+rs1.getString(2)+" "+rs1.getString(3)+" "+rs1.getString(4));
                   }
    }
}









Related Tutorials/Questions & Answers:
JDBC and Aggregate values
JDBC and Aggregate values  How to get the aggregate value using JDBC... only one row, only one column in return and I want to get that data using JDBC. How may I do it?   Java JDBC retrieve selected value import java.sql.
SQL Aggregate Functions First
SQL Aggregate Functions First       SQL Aggregate Function First, that performs calculation of data. The SQL aggregate function retrieve a single value, by calculate from
Advertisements
SQL Aggregate Functions Group By
SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate... of column values. Understand with Example The Tutorial grasp you
SQL Aggregate Functions First
SQL Aggregate Functions First       SQL Aggregate Function First, that performs calculation of data. The SQL aggregate function retrieve a single value, by calculate from
Aggregate Functions
Aggregate Functions       In this section we are going to illustrate aggregate function... of: "How to use aggregate functions in MySQL?" For all of the above
SQL Aggregate Concatenate
SQL Aggregate Concatenate         SQL Aggregate Concatenate provides you a concatenated record...;Understand with Example The Tutorial illustrate an example from SQL Aggregate
SQL Aggregate Max
SQL Aggregate Max       SQL Aggregate Max is used to find the highest value of the column in a table... Aggregate Max. In this Example we create a table Stu_Table. The create table
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... with Example The Tutorial help you to understand an Example from 'SQL Aggregate
SQL Aggregate Sum
SQL Aggregate Sum       The SQL Aggregate Sum Function is a part of Aggregate Function that is used... The Tutorial grasp you with the concept on 'SQL Aggregate Sum'. In this Tutorial, we
Hibernate Aggregate Functions
Hibernate Aggregate Functions In this tutorial you will learn about aggregate functions in Hibernate In an aggregate functions values of columns... supports various useful Aggregate functions some of these are : avg(...), avg
can i insert values into two tables by a query - JDBC
can i insert values into two tables by a query  hi all, can i insert values into two tables by a query Thanks Bala k
Hibernate Criteria Aggregate Functions Example
Hibernate Criteria Aggregate Functions Example  I need Hibernate Criteria Aggregate Functions Example program with source code, I want example of Hibernate Criteria Aggregate Functions? Can anyone share me the source code
SQL Aggregate Functions List
SQL Aggregate Functions List       SQL Aggregate Functions List describe you the Aggregate Function List Queries. The Aggregate Function include the average, count, min, max, sum etc
SQL Aggregate Functions Group By
SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate... of column values. Understand with Example The Tutorial grasp you
SQL Aggregate Sum
SQL Aggregate Sum       The SQL Aggregate Sum Function is a part of Aggregate Function... with Example The Tutorial grasp you with the concept on 'SQL Aggregate Sum
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause return you the aggregate sum of the records based on the condition specified in Where Clause condition
SQL Aggregate Queries
SQL Aggregate Queries       SQL Aggregate Queries show you the list of Aggregate Function that include... The Tutorial illustrate an example from 'SQL Aggregate Queries'. To understand
SQL Aggregate Functions
SQL Aggregate Functions       SQL Aggregate Functions is built in function that is used... illustrate an example from 'SQL Aggregate Function'. To understand and grasp
SQL Aggregate Max
SQL Aggregate Max       SQL Aggregate Max is used to find the highest value of the column... from SQL Aggregate Max. In this Example we create a table Stu_Table
MySQL Aggregate Function
MySQL Aggregate Function       This example illustrates how use the aggregate function in the MySQL Query. In this example we use the aggregate function ('COUNT
SQL Aggregate Concatenate
SQL Aggregate Concatenate         SQL Aggregate Concatenate provides you... SQL Aggregate Concatenate. To grasp this example, we create a table 'Stu
SQL Aggregate Concatenation
SQL Aggregate Concatenation       SQL Aggregate Concatenation are used to perform operation... The Tutorial illustrate an example from 'SQL Aggregate Concatenation'. To understand
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key... I ma getting wrong sum values of i.InvoiceQuantity,p.IssueQuantity column
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key... I ma getting wrong sum values of i.InvoiceQuantity,p.IssueQuantity column
Sql aggregate function with left join wrong output
Sql aggregate function with left join wrong output    I have three tables Stock,InwardEntry,IssueToProd. Part_no in stock is a primary key... I ma getting wrong sum values of i.InvoiceQuantity,p.IssueQuantity column
Aggregate Functions in SQL, SQL Tutorial
Aggregate Functions       In this section we are going to illustrate aggregate function, with the help...; For example we just take a Employee table and use the aggregate function SUM
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... with Example The Tutorial help you to understand an Example from 'SQL Aggregate
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause is used... with Example The Tutorial illustrate an example  from SQL Aggregate Function
Hibernate Criteria Aggregate Functions
Hibernate Criteria Aggregate Functions The Hibernate Criteria Aggregate Function Supports the following function min(), max(), sum(), avg(), count(). These functions are of Projections class. Following are the way to use
Hibernate Avg() Function (Aggregate Functions)
Hibernate Avg() Function (Aggregate Functions)  ... to use the avg() function. Hibernate supports multiple aggregate functions. When they are used in HQL queries, they return an aggregate value ( such as avg
Hibernate Max() Function (Aggregate Functions)
Hibernate Max() Function (Aggregate Functions... to use the Max() function. Hibernate supports multiple aggregate functions. When they are used in HQL queries, they return an aggregate value ( such as avg
Tutorials   
Java Spring Hibernate Struts Training how to retrieve text and images from mysql database and show on html page using jsp servlet How to install Neo4j on Ubuntu 15.10? please help me in these prog MYSQL - mysql copy table to another table example by creating new table solution for mapping hibernate and pojos from net beans through database Connect GWT application with Oracle inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store inventory System of Medical Store This code have created jTable that connected with a database.every cell of last column have a button.But this button doesn't work properly.Where is the error java program Java Database Program jdbc Database connection class in a live project ..?? What is JDBC architecture? Unable to Create DSN for excel to ms access importing data and edit that data Database Scrolling Buttons how to use foreign key in java How to delete content of a log file from linux terminal? JSP-Oracle connectivity Student Management System Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same crud operations with foreign key constraint. I really need help with this assignment question Please help me out Please Backup Failed Mysqldump Got Errno 28 On Write Upgrade MySQL 5.1 to 5.5 in cpanel mysqldump all databases com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'jpa.sequence' doesn't exist persistence xml class element persistence.xml for MySQL MySQL JDBC Driver pom dependency code Blob column jdk6 and oracle 8i connexion oracle 8i et jdk6 java [ cannot retrive date from sql ] why?? Order Entry System How to threow timeout exception when DB is not responding How to threow timeout exception when DB is not responding This is the employee form to add data to mysql database but I got error of NullPointerException, Is this write code please give me feedback as soon as possible make a method which takes user name & pwd as parameter & validate them against the database. If the corresponding user exist return true otherwise false. prabhakar validating credentials and displaying error message in login .jsp if not valid JDBC jdbc jdbc code register servlet vibhu connectiondetails from vibhu

Ads

 
Advertisement null

Ads