80,000 and displays names of employees with salary < 30,000 by querying the Employee table. 3) Displays the names of all employees by querying the Employee table. 4) Updates the salary to 80,000 for employees with salary < 50,000 and displays all records of the Employee table."> 80,000 and displays names of employees with salary < 30,000 by querying the Employee table. 3) Displays the names of all employees by querying the Employee table. 4) Updates the salary to 80,000 for employees with salary < 50,000 and displays all records of the Employee table.">
[go: up one dir, main page]

0% found this document useful (0 votes)
61 views3 pages

JDBC Solutions

The document provides 4 examples of JDBC programs in Java: 1) Displays the names of all students studying BCA by querying the Student table. 2) Deletes employees with salary > 80,000 and displays names of employees with salary < 30,000 by querying the Employee table. 3) Displays the names of all employees by querying the Employee table. 4) Updates the salary to 80,000 for employees with salary < 50,000 and displays all records of the Employee table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

JDBC Solutions

The document provides 4 examples of JDBC programs in Java: 1) Displays the names of all students studying BCA by querying the Student table. 2) Deletes employees with salary > 80,000 and displays names of employees with salary < 30,000 by querying the Employee table. 3) Displays the names of all employees by querying the Employee table. 4) Updates the salary to 80,000 for employees with salary < 50,000 and displays all records of the Employee table.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Write a JDBC Program in java to display the names of all


Students studying in BCA

import java.io.IOException;
import java.sql.*;

public class Student


{
public static void main(String[] args) throws SQLException,
ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:DSN");
Statement st = conn.createStatement();
String sql = "Select * from Student where Programme like 'BCA'";
ResultSet rs = st.executeQuery(sql);

while(rs.next()){
System.out.println("\n"+ rs.getString(2));
}

}
}

2. Write a JDBC program to delete Write a JDBC Program in java to


delete employees with salary>80000, and display the names of
all employees where salary<30000
import java.io.IOException;
import java.sql.*;

public class Student_del


{
public static void main(String[] args) throws SQLException,
ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:DSN");
Statement st = conn.createStatement();
String sql = "delete from Employee where Salary>80000";
st.executeUpdate(sql);

sql = "Select * from Employee where Salary<30000";


ResultSet rs= st.executeQuery(sql);

Prof. Monika Gadre


while(rs.next()){
System.out.println("\n"+
rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));

}
}
}

3. Write a JDBC Program in java to display the names of all


Employees
import java.io.IOException;
import java.sql.*;

public class Employee


{
public static void main(String[] args) throws SQLException,
ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:DSN");
Statement st = conn.createStatement();
String sql = "Select * from Employee";
ResultSet rs = st.executeQuery(sql);

while(rs.next()){
System.out.println("\n"+
rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));
}

}
}

4. Write a JDBC Program in java to update salary of employees


whose salary is less than Rs.50000 and display all the records
of Employee table
import java.io.IOException;
import java.sql.*;

public class Employee


{
public static void main(String[] args) throws SQLException,
ClassNotFoundException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Prof. Monika Gadre


Connection conn = DriverManager.getConnection("jdbc:odbc:DSN");
Statement st = conn.createStatement();
String sql = "Update Employee set Salary=80000 where
Salary<50000";
st.executeUpdate(sql);

sql = "Select * from Employee";


ResultSet rs= st.executeQuery(sql); ;

while(rs.next()){
System.out.println("\n"+
rs.getString(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));
}

}
}

Prof. Monika Gadre

You might also like