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 :