100% found this document useful (2 votes)
1K views4 pages

Java SQL Programs for Student and Employee Tables

The document contains code for three Java programs: 1) A program to create a Student table in a database and insert records. It creates a table with columns for student ID, name, and branch, and inserts two records. 2) A program to create an Employee table with columns for employee ID and name. 3) A program to display the name and roll number of students from a student table whose percentage is greater than 70. It connects to a database, runs a SQL query, and prints the results.

Uploaded by

nstrnsdtn
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
100% found this document useful (2 votes)
1K views4 pages

Java SQL Programs for Student and Employee Tables

The document contains code for three Java programs: 1) A program to create a Student table in a database and insert records. It creates a table with columns for student ID, name, and branch, and inserts two records. 2) A program to create an Employee table with columns for employee ID and name. 3) A program to display the name and roll number of students from a student table whose percentage is greater than 70. It connects to a database, runs a SQL query, and prints the results.

Uploaded by

nstrnsdtn
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/ 4

Name : Ayush Maroti wadje Roll no. : 76 Practical no.

: 18

X. PROGRAM CODE : 1. Write a Program to create a Student Table in database and insert
a record in a Student table

import java.sql.*;
public class DTA
{
public static void main(String[] args){
try{
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D://Employee1.accdb");
Statement s = con.createStatement();
s.execute("Create Table SData (STUD_ID int, STUD_Name varchar(255),BRANCH
varchar(255))");
s.execute("Insert into SData values((101,'Kaif','CO'),(102,'Irfan','IT'))");
s.execute("select * from SData");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println("Id of the Student: " + rs.getString(1) );
System.out.println("Name of Student: " + rs.getString(2) );
System.out.println("Branch of Student: " + rs.getString(3) );
System.out.println("********************************************" );}

s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}
1.Develop a program to create employee table In database having two columns “emp-id”
and “emp_name”.

Ans:-
import java.sql.*;
public class DTA1
{
public static void main(String[] args){
try{
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D://Employee.accdb");
Statement s = con.createStatement();
s.execute("Create Table Emp1 (EMP_ID int, EMP_Name varchar(255))");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println("Id of the book: " + rs.getString(1) );
System.out.println("Name of book: " + rs.getString(2) );
System.out.println("________________________________________" );}
s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}
Output
2.Develop a program to display the name and roll no. of students from “student table”
having percentage >70

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class PraP


{
public static void main(String[] args){
try{
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D://student.accdb");
Statement s = con.createStatement();
s.execute("select * from Stud_Data where Percentage < 70 ");
ResultSet rs = s.getResultSet();
if (rs != null){
while ( rs.next() ) {
System.out.println(" " );
System.out.println("Id of the product: " + rs.getString(1) );
System.out.println("Name of Student: " + rs.getString(2) );
System.out.println("Branch : " + rs.getString(3) );
System.out.println("Percentage : " + rs.getString(4) );
System.out.println(" " );}
s.close();
con.close();}}
catch (Exception err){
System.out.println("ERROR: " +err);
}
}
}

Output :

You might also like