0% found this document useful (0 votes)
112 views1 page

Slip3 1

This JDBC program uses a SQL query to retrieve and display the employee number, name, department, and salary of employees whose department is "Computer Science" from an emp1 database table. The program establishes a connection to the database, executes the query, iterates through the result set to print out the retrieved field values, and closes the connection. It outputs the employee details of three employees from the Computer Science department.

Uploaded by

Prasad Dutande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views1 page

Slip3 1

This JDBC program uses a SQL query to retrieve and display the employee number, name, department, and salary of employees whose department is "Computer Science" from an emp1 database table. The program establishes a connection to the database, executes the query, iterates through the result set to print out the retrieved field values, and closes the connection. It outputs the employee details of three employees from the Computer Science department.

Uploaded by

Prasad Dutande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment:3

-----------------------------------------------------------------------------------------------------------------------------------------

Q.1:Write JDBC Program to displays the details of Employees(eno,ename,department,sal)whose


department isComputer Science.
Ans:
import java.sql.*;
class Slip3J1
{
public static void main(String args[])
{
Connection cn;
Statement st;
ResultSet rs;
String s;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc:Detail");
st=cn.createStatement();
s="select * from emp1 where dept='Computer Science'";
rs=st.executeQuery(s);
System.out.println("Displayin Details of Computer Science Department");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+"
"+rs.getString(3)+" "+rs.getInt(4));
}
cn.close();
st.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
OUTPUT:
C:\Users\Onkar\Desktop>javac Slip3J1.java
C:\Users\Onkar\Desktop\>java Slip3J1
Displayin Details of Computer Science Department
101 Gourav Computer Science 15000
103 Ajinkya Computer Science 12500
105 Shubham Computer Science 16500

You might also like