JDBC and Aggregate values

JDBC and Aggregate values

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?

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 ExampleADS_TO_REPLACE_1
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
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
ModuleNotFoundError: No module named 'aggregate'
ModuleNotFoundError: No module named 'aggregate'  Hi, My Python... 'aggregate' How to remove the ModuleNotFoundError: No module named 'aggregate' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'aggregate'
ModuleNotFoundError: No module named 'aggregate'  Hi, My Python... 'aggregate' How to remove the ModuleNotFoundError: No module named 'aggregate' error? Thanks   Hi, In your python environment you
Aggregate Functions
Aggregate Functions       In this section we are going to illustrate aggregate function... is the video tutorial of: "How to use aggregate functions in MySQL?"
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... Aggregate Functions'. To understand this, we create a table 'Stu_Table
SQL Aggregate Sum
SQL Aggregate Sum       The SQL Aggregate Sum Function is a part of Aggregate Function that is used..._TO_REPLACE_1 The Tutorial grasp you with the concept on 'SQL Aggregate Sum
SQL Aggregate Concatenate
SQL Aggregate Concatenate         SQL Aggregate Concatenate provides you a concatenated record... SQL Aggregate Concatenate. To grasp this example, we create a table 'Stu
SQL Aggregate Max
SQL Aggregate Max       SQL Aggregate Max is used to find the highest value of the column in a table... an example from SQL Aggregate Max. In this Example we create a table Stu_Table
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 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 Sum
SQL Aggregate Sum       The SQL Aggregate Sum Function is a part of Aggregate Function... with ExampleADS_TO_REPLACE_1 The Tutorial grasp you with the concept on 'SQL Aggregate
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 Group By
SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate... of column values. Understand with ExampleADS_TO_REPLACE_1
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
ModuleNotFoundError: No module named 'django-aggregate-if'
ModuleNotFoundError: No module named 'django-aggregate-if'  Hi, My... named 'django-aggregate-if' How to remove the ModuleNotFoundError: No module named 'django-aggregate-if' error? Thanks   Hi
ModuleNotFoundError: No module named 'django-aggregate-if'
ModuleNotFoundError: No module named 'django-aggregate-if'  Hi, My... named 'django-aggregate-if' How to remove the ModuleNotFoundError: No module named 'django-aggregate-if' error? Thanks   Hi
ModuleNotFoundError: No module named 'aggregate-prefixes'
ModuleNotFoundError: No module named 'aggregate-prefixes'  Hi, My... named 'aggregate-prefixes' How to remove the ModuleNotFoundError: No module named 'aggregate-prefixes' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-aggregate-if'
ModuleNotFoundError: No module named 'django-aggregate-if'  Hi, My... named 'django-aggregate-if' How to remove the ModuleNotFoundError: No module named 'django-aggregate-if' error? Thanks   Hi
ModuleNotFoundError: No module named 'aggregate-prefixes'
ModuleNotFoundError: No module named 'aggregate-prefixes'  Hi, My... named 'aggregate-prefixes' How to remove the ModuleNotFoundError: No module named 'aggregate-prefixes' error? Thanks   Hi, In your
SQL Aggregate Max
SQL Aggregate Max       SQL Aggregate Max is used to find the highest value of the column... illustrate an example from SQL Aggregate Max. In this Example we create a table
SQL Aggregate Functions
SQL Aggregate Functions       SQL Aggregate Functions is built in function that is used... The Tutorial illustrate an example from 'SQL Aggregate Function
SQL Aggregate Queries
SQL Aggregate Queries       SQL Aggregate Queries show you the list of Aggregate Function that include..._TO_REPLACE_1 The Tutorial illustrate an example from 'SQL Aggregate Queries
SQL Aggregate Concatenate
SQL Aggregate Concatenate         SQL Aggregate Concatenate provides you... an example from SQL Aggregate Concatenate. To grasp this example, we
SQL Aggregate Concatenation
SQL Aggregate Concatenation       SQL Aggregate Concatenation are used to perform operation... with Example The Tutorial illustrate an example from 'SQL Aggregate Concatenation
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 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
JDBC
JDBC save a data in the database  I need a code to save a data... between java and mysql using JDBC and saves the data into the database. import...) { System.out.println("Inserting values in Mysql database table!"); Connection
JDBC
JDBC code to save a data in the database  I need a code to save... the connection between java and mysql using JDBC and saves the data into the database...[] args) { System.out.println("Inserting values in Mysql database table
ModuleNotFoundError: No module named 'Vectors-of-Locally-Aggregate-Concepts'
ModuleNotFoundError: No module named 'Vectors-of-Locally-Aggregate-Concepts...: ModuleNotFoundError: No module named 'Vectors-of-Locally-Aggregate-Concepts' How to remove the ModuleNotFoundError: No module named 'Vectors-of-Locally-Aggregate
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause is used... Aggregate Function Where Clause. To understand and grasp example we create a table
jdbc
jdbc  how to update int values of ms-access in jdbc program?   In MS Access database, use Number data type for int values. import... =DriverManager.getConnection("jdbc:odbc:access","",""); Statement st=null; st
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... Aggregate Functions'. To understand this, we create a table 'Stu_Table
jdbc
using jdbc connection   import java.sql.*; public class CreateTable... = DriverManager.getConnection("jdbc:odbc:student"); Class.forName... into employee (empid,empname ) values (1,'Roseindia')"); System.out.println("Data
jdbc
oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection("jdbc:oracle:thin... values("+eno+","+name+","+sal+")"; System.out.println(query); PreparedStatement
Aggregate Functions in SQL, SQL Tutorial
Aggregate Functions       In this section we are going to illustrate aggregate function, with the help... the aggregate function SUM on the field "Salary" to find out the total
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
Hibernate Min() Function (Aggregate Functions)
Hibernate Min() Function (Aggregate Functions)  ... the Min() function. Hibernate supports multiple aggregate functions. When they are used in HQL queries, they return an aggregate value ( such as avg(...), sum
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc - JDBC
field should be shown to insert a column in HTML )how to get those values in JSP to create a table. 2)how desc can be written in JDBC concepts  ...) { System.out.println("Inserting values in Mysql database table!"); Connection con
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
JDBC
JDBC  How to fetch values from database based on dropdown list selection?   import java.sql.*; import java.awt.*; import java.util.... = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root

Ads