JDBC EXAMPLE FOR SELECT | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Tuesday, May 20, 2014

JDBC EXAMPLE FOR SELECT



PROGRAM:

import java.sql.*;
import java.io.*;
class EmpSelect
{
            public static void main(String a[])throws Exception
            {
try
{
                                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                    Connection c=DriverManager.getConnection("jdbc:odbc:Empsn");
                                    Statement s=c.createStatement();
                                    String str="select * from emp";
                                    ResultSet r=s.executeQuery(str);
                                    while(r.next())
                                    {
                                    Int id=r.getInt(1);
                                    String name=r.getString(2);
                                    String de=r.getString(3);
                                    double sal=r.getDouble(4);
                                    double hr=r.getDouble(5);
                                    double da=r.getDouble(6);
                                    double loan=r.getDouble(7);
                                    double n=(sal+hr+da)-loan;
                                    System.out.println("Empid:" +id);
                                    System.out.println("Name: "+name);
                                    System.out.println("Designation: "+de);
                                    System.out.println("Salary: "+n);
                                    }         
}

                        catch(Exception e)
{
System.out.println(e);
}
         }
}







TABLE CREATION IN MS-ACCESS

Id
Name
De
Sal
Hr
Da
Loan
101
Martin
manager
10000
5000
750
750
102
Smith
asstmanager
7500
2500
1000
1000

OUTPUT:

Empid: 101
Name: Martin
Designation: Manager
Salary: 15000

Empid: 102
Name: Smith
Designation: AsstManager
Salary: 10000

No comments:

Post a Comment

Thanks for your valuable comments

Followers