Where clause

Where clause

I have doubt in Where clause .. i got a Employid from user and check the id and display the details of that id what can i do?

View Answers

June 15, 2012 at 12:42 PM

The WHERE clause is used to filter records.It is used to extract only those records that fulfill a specified criterion.

SQL WHERE Syntax:

SELECT column_name(s)
FROM table_name
WHERE column_name = value;

Example:

In the given example, we have accepted the id from the user and retrieve the record of that user from the database.

import java.sql.*;
import java.util.*;

class RetrieveData 
{
    public static void main(String[] args) throws Exception
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter id: ");
        int id=input.nextInt();
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from data where id="+id+"");

        while(rs.next()){
            String name=rs.getString("name");
            String address=rs.getString("address");
            String contact=rs.getString("contactNo");
            String email=rs.getString("email");

            System.out.println(name+" \t "+address+" \t "+contact+" \t "+email);

        }
    }
}









Related Tutorials/Questions & Answers:
Where clause
Where clause  I have doubt in Where clause .. i got a Employid from...; The WHERE clause is used to filter records.It is used to extract only those records that fulfill a specified criterion. SQL WHERE Syntax: SELECT column
Where and Having clause
Where and Having clause   hii, What is the difference between where and having clause?   hello,ADS_TO_REPLACE_1 WHERE clause is used... before GROUP BY clause. HAVING clause is used to impose condition on GROUP
Advertisements
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?  What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?   Hi, Both HAVING and WHERE clause used for specifying the search condition in SQL
where clause in select statement
where clause in select statement  In Mysql,I write the following query: select * from emp where designation = "MANAGER" But the actual value... nly if the where condition is "manager" and not "MANAGER
Where clause with query in MySQL
Where clause with query in MySQL  Hi, I want to learn the where... is the various example of where clause: Suppose we have following table: mysql> select... (0.00 sec) Following shows more uses of where clause: mysql> select * from
Where Clause in SQL
Where Clause in SQL       The Where clause in SQL query is used  with the SELECT keyword.' Where' clause search the data with a particular condition. In case the data
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
Mysql Date in where clause
Mysql Date in where clause     ... records from table employee1 on the basis of condition specified in WHERE clause... Mysql data in Where clause. The given Query create table employee1 is used
HQL Where Clause Example
HQL Where Clause Example       Where Clause is used to limit the results returned from... lngInsuranceId='1'ADS_TO_REPLACE_1 Where Clause can be used with or without Select
Hibernate WHERE Clause
Hibernate WHERE Clause In this tutorial you will learn how to use HQL where clause. Use of WHERE clause in hibernate is as same as it used in SQL... will demonstrate you how a HQL where clause can be used. To achieve the solution
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
JDBC: WHERE Clause Example
JDBC: WHERE Clause Example In this section, we will discuss how to use WHERE.... WHERE Clause : MySql Where Clause is used to write some condition and data... static void main(String[] args) { System.out.println("Use of WHERE Clause
Using WHERE Clause in JDBC
Using WHERE Clause in JDBC    Where... conditions. It allows to filter the data from a table, a WHERE clause can be added to the SELECT statement. The WHERE clause searches the specific results
JPA Query with where clause and group by function
JPA Query with where clause and group by function  Any thing wrong in my JPA Query. TypedQuery<RaBdrRating> uQuery = (TypedQuery<...(charge),COUNT(activePackage) FROM User WHERE callType = :callType and startDate
PHP SQL Query Where Clause
PHP SQL Query Where Clause       This example illustrates how to create and execute the sql query with where clause. To understand how to display the result returned 
What is the difference between IN and BETWEEN, that are used inside a WHERE clause?
What is the difference between IN and BETWEEN, that are used inside a WHERE clause?  What is the difference between IN and BETWEEN, that are used inside a WHERE clause?   Hi, The BETWEEN clause is used to fetch a range
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... in the 'Stu_Name'. In order to overcome, we use the WHERE clause. The Syntax
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
HOW CN I USE WHERE AND BETWEEN CLAUSE SIMULTANEOUSLY... IN MYSQL
HOW CN I USE WHERE AND BETWEEN CLAUSE SIMULTANEOUSLY... IN MYSQL  sir, how can i use WHERE and BETWEEN clause simultaneously..? my tables details... WHERE _exp_date BETWEEN ('2009-07-01' AND '2011-07-30') AND _exp_for_id = 1
how to use comma separated value list in the where clause oracle
how to use comma separated value list in the where clause oracle  Hi, how to use comma separated value list in the where clause oracle Thanks   HI, Following code will help you: select * from employee where id
PHP WHERE clause example to fetch records from Database Table
different actions in MYSQL Database Tables. PHP WHERE Clause is one of them. We can use the WHERE clause in PHP & MYSQL to  add, edit or delete... the WHERE Clause in PHP. Here is an example of how you can write the WHERE Clause
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.  Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL
Explain the use of the ‘LIKE’ keyword used in the WHERE clause? Explain wildcard characters in SQL.
Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL.  Explain the use of the ?LIKE? keyword used in the WHERE clause? Explain wildcard characters in SQL
WHERE Statement in SQL
WHERE Clause in SQL        WHERE clause is used with the SELECT keyword. ' Where' is a clause which is used for searching the data with a particular condition.  
Mysql Where
Clause. The Where Clause restricts the select query and shows you only the records specified in the Where Clause conditions. Understand with ExampleADS... (0.01 sec) Query for using where clause:ADS_TO_REPLACE_4
Mysql where
on the condition specified in Where CLAUSE. Understand with ExampleADS... | +-------+---------+--------+ 9 rows in set (0.01 sec) Query for using where clause... salary is 20000 as specified in WHERE Clause. mysql>
Mysql Where Statement
on the basis of specified condition in Where Clause. The Where Clause restricts... The Query  Where Clause returns only those records from table specified in Where... username is 'srbh' as specified in Where Clause. mysql> select * from
Php Sql Where
Php Sql Where This example illustrates how to use the WHERE clause in the UPDATE query in PHP. In this example we create a UPDATE query with WHERE clause to update the field emp_name where name is 'amar'. In the figure below the first
PHP SQL Where
definition based on the condition specified in Where Clause. The PHP SQL Where allows you to update the field based on the condition specified in Where Clause...' to sandeep based on the 'emp_id = 1' condition specified in Where Clause. The While
SQL Backup query with where statement
SQL Backup query with where statement       SQL Backup query with where statement  is used to construct a backup table using where clause. The Where Clause
MySQL Case In Where Clause
MySQL Case In Where Clause       This example illustrates how to use case statement where clause... 'case' and 'where' clause: SELECT daysName, CASE daysName    WHEN
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
SQL Aggregate Functions In Where Clause
SQL Aggregate Functions In Where Clause       SQL Aggregate Function In Where Clause return... in the 'Stu_Name'. In order to overcome, we use the WHERE clause
Hibernate In Clause
In this section we will introduce concept of Hibernate In Clause
ModuleNotFoundError: No module named 'clause'
ModuleNotFoundError: No module named 'clause'  Hi, My Python... 'clause' How to remove the ModuleNotFoundError: No module named 'clause'... to install padas library. You can install clause python with following command
SQL HAVING Clause
condition for a group or aggregate. The HAVING clause works with where... set. The Where clause is applicable to individual rows.  Create... SQL HAVING Clause      
SQL HAVING Clause
condition for a group or aggregate. The HAVING clause works with where.... The Where clause is applicable to individual rows.  Create Table Stu... SQL HAVING Clause      
select clause in hibernate
select clause in hibernate  Example of select clause of hibernate?   Select clause is used for selection of records from a database... This is your select clause, picking the employee details as employee name,salary and date
HQL from clause Example
HQL from clause Example     ... clause. The from clause is the simplest possible Hibernate Query. Example of from clause is: from Insurance insuranceADS_TO_REPLACE_1 Here is the full code
HAVING Clause in JPQL (Java Persistence Query Language)
to each group of grouped table, much as a WHERE clause is applied to a select list... HAVING Clause in JPQL (Java Persistence Query Language... to use of HAVING Clause in jpql (Java Persistence Query Language). HAVING Clause
php MySQL order by clause
php MySQL order by clause:       In SQL generally we use three clauses, select ,from, and where. .... Order by is one of the important clause of SQL. Order by clause is used to sort
JDBC: LIKE Clause Example
JDBC: LIKE Clause Example In this section, you will learn how to use LIKE Clause for selection of table records using JDBC API. LIKE Clause : Like Clause is used for comparing part of string. For pattern matching we use
Hibernate SELECT Clause
); } //SELECT clause with from & where Query selectClause1...Hibernate SELECT Clause In this tutorial you will learn how to use HQL select clause. Use of SELECT clause in hibernate is as same as it used in SQL
HQL Between clause, HQL Between example
HQL Between clause example In this tutorial you will learn how to use HQL Between clause to select a range of entity falling between 2 and 6. You can... and 6. The HQL Between used for this purpose is: // Create HQL Between clause
Hibernate ORDER BY Clause
Hibernate ORDER BY Clause In this tutorial you will learn about HQL ORDER BY clause. Purpose for using ORDER BY clause is similar to that it is used in SQL... how a HQL order by clause can be used. To achieve the solution
THE key Word WHERE in SQL, SQL Tutorial
WHERE Clause in SQL        WHERE clause is used with the SELECT keyword. ' Where' is a clause which is used for searching the data with a particular condition.  
HQL Group By Clause Example
HQL Group By Clause Example       Group by clause is used to return the aggregate values by grouping on returned component. HQL supports Group By Clause. In our example we

Ads