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



Home Answers Viewqa JDBC JDBC and Aggregate values

Have Programming Question? Ask it here!
 
 
 


D Student
JDBC and Aggregate values
1 Answer(s)      3 years and 5 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?


Advertisement
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
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
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 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
Aggregate Functions
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
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
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
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 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
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
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
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc
jdbc  display the records using index in jdbc
JDBC
JDBC  why we use batch in jdbc
Hibernate Aggregate Functions(Associations and Joins)
Hibernate Aggregate Functions(Associations and Joins... understand about the aggregate function of Hibernate with the help of example.  In Hibernate HQL queries are capable of returning the results of the aggregate
JDBC
JDBC  How to add set of queries in a single query in JDBC
jdbc
("jdbc:odbc:student"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver... successfully!"); st.executeUpdate("insert into employee (empid,empname ) values
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
JDBC
JDBC  How to fetch values from database based on dropdown list...); } } In the above code, the values of i and j are function arguments.   import...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql
JDBC
JDBC  can u send me the code of jdbc how to join two tables that are in relation
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
jdbc
jdbc  is it possible to use doget & dopost method with jdbc to call in a servlet programe
JDBC
JDBC  in class.forname which driver name we are writing for the connection from jdbc to sqlserver 2008
 

 

 

DMCA.com