Thursday, 22 December 2016
Wednesday, 21 December 2016
Thursday, 15 December 2016
Class and object in JAVA programming
import java.io.*;
import java.util.*;
//set path = C:\Program Files\Java\jdk1.7.0_51\bin
class readinput1
{
int id,size;
float rate;
String shirtmodel,color;
readinput1()
{
id=0;
size=1;
rate=100;
shirtmodel="AAA";
color="red";
}
readinput1(String col)
{
this();
color=col;
}
readinput1(String col,int id1)
{
this();
this.id=id1;
color=col;
}
readinput1(String col,int id1,String model,int size1)
{
this();
id=id1;
color=col;
size=size1;
shirtmodel=model;
}
readinput1(String col,int id1,String model,int size1,float rate1)
{
id=id1;
color=col;
size=size1;
shirtmodel=model;
rate=rate1;
}
void display()
{
System.out.println("Rate"+rate);
System.out.println("ID"+id);
System.out.println("Shirt Model"+shirtmodel);
System.out.println("Shirt color"+color);
System.out.println("Shirt Size"+size);
}
};
public class readinput
{
public static void main(String[] args) throws IOException
{
int id,size;
float rate;
String shirtmodel,color;
BufferedReader bin;
DataInputStream ds;
bin = new BufferedReader(new InputStreamReader(System.in));
//System.out.println("Enter number 1 to get into your class");
//id = Integer.parseInt(bin.readLine());
//rate = Float.parseFloat(bin.readLine());
ds=new DataInputStream(System.in);
System.out.println("Enter id");
id=Integer.parseInt(ds.readLine());
Scanner scan = new Scanner(System. in);
System.out.println("Enter shirt model");
shirtmodel = scan.next();
System.out.println("Enter color");
color = scan.next();
//rate=scan.nextFloat();
System.out.println("Enter the shirt size");
size=scan.nextInt();
System.out.println("Enter the rate ");
rate=Float.parseFloat(ds.readLine());
readinput1 ripss=new readinput1();
System.out.println("Default Constructor ");
ripss.display();
System.out.println("Enter the choice(1/2/3/4) ");
int ch=Integer.parseInt(ds.readLine());
switch(ch)
{
case 1: System.out.println("change color using single Parameter Constructor ");
readinput1 rips=new readinput1(color);rips.display();break;
case 2: System.out.println("change color and id using two Parameters Constructor ");
readinput1 rip=new readinput1(color,id);rip.display();break;
case 3: System.out.println("change color,id,shirtmodel,size using Parameters(4) Constructor ");
readinput1 rip1=new readinput1(color,id,shirtmodel,size);rip1.display();break;
case 4: System.out.println("change color,id,shirtmodel,size,rate using Parameters(5) Constructor ");
readinput1 rip2=new readinput1(color,id,shirtmodel,size,rate);rip2.display();break;
default: System.out.println("Enter the valid input from 1 to 4 for choice ");
}
}
}
import java.util.*;
//set path = C:\Program Files\Java\jdk1.7.0_51\bin
class readinput1
{
int id,size;
float rate;
String shirtmodel,color;
readinput1()
{
id=0;
size=1;
rate=100;
shirtmodel="AAA";
color="red";
}
readinput1(String col)
{
this();
color=col;
}
readinput1(String col,int id1)
{
this();
this.id=id1;
color=col;
}
readinput1(String col,int id1,String model,int size1)
{
this();
id=id1;
color=col;
size=size1;
shirtmodel=model;
}
readinput1(String col,int id1,String model,int size1,float rate1)
{
id=id1;
color=col;
size=size1;
shirtmodel=model;
rate=rate1;
}
void display()
{
System.out.println("Rate"+rate);
System.out.println("ID"+id);
System.out.println("Shirt Model"+shirtmodel);
System.out.println("Shirt color"+color);
System.out.println("Shirt Size"+size);
}
};
public class readinput
{
public static void main(String[] args) throws IOException
{
int id,size;
float rate;
String shirtmodel,color;
BufferedReader bin;
DataInputStream ds;
bin = new BufferedReader(new InputStreamReader(System.in));
//System.out.println("Enter number 1 to get into your class");
//id = Integer.parseInt(bin.readLine());
//rate = Float.parseFloat(bin.readLine());
ds=new DataInputStream(System.in);
System.out.println("Enter id");
id=Integer.parseInt(ds.readLine());
Scanner scan = new Scanner(System. in);
System.out.println("Enter shirt model");
shirtmodel = scan.next();
System.out.println("Enter color");
color = scan.next();
//rate=scan.nextFloat();
System.out.println("Enter the shirt size");
size=scan.nextInt();
System.out.println("Enter the rate ");
rate=Float.parseFloat(ds.readLine());
readinput1 ripss=new readinput1();
System.out.println("Default Constructor ");
ripss.display();
System.out.println("Enter the choice(1/2/3/4) ");
int ch=Integer.parseInt(ds.readLine());
switch(ch)
{
case 1: System.out.println("change color using single Parameter Constructor ");
readinput1 rips=new readinput1(color);rips.display();break;
case 2: System.out.println("change color and id using two Parameters Constructor ");
readinput1 rip=new readinput1(color,id);rip.display();break;
case 3: System.out.println("change color,id,shirtmodel,size using Parameters(4) Constructor ");
readinput1 rip1=new readinput1(color,id,shirtmodel,size);rip1.display();break;
case 4: System.out.println("change color,id,shirtmodel,size,rate using Parameters(5) Constructor ");
readinput1 rip2=new readinput1(color,id,shirtmodel,size,rate);rip2.display();break;
default: System.out.println("Enter the valid input from 1 to 4 for choice ");
}
}
}
Friday, 14 October 2016
Image Processing :-foreground detection code
%foreground detection
close all
f=imread('d:\rabit.jpg');
grayrabit = rgb2gray(f);
mask = grayrabit>170;
imshow(mask);
imwrite(mask,'d:\maskrabit.jpg','jpg');
f3=imread('d:\maskrabit.jpg');
f3=im2bw(f3);
fr=f(:,:,1);
fg=f(:,:,2);
fb=f(:,:,3);
frm=immultiply(fr,f3);
fgm=immultiply(fg,f3);
fgb=immultiply(fb,f3);
foreground=cat(3,frm,fgm,fgb);
imwrite(foreground,'d:\forerabit.jpg','jpg');
figure,imshow(f),figure,imshow(foreground)
%background detection
f=imread('d:\rabit.jpg');
grayrabit = rgb2gray(f);
mask = grayrabit<170;
imshow(mask);
imwrite(mask,'d:\maskrabit.jpg','jpg');
f3=imread('d:\maskrabit.jpg');
f3=im2bw(f3);
fr=f(:,:,1);
fg=f(:,:,2);
fb=f(:,:,3);
frm=immultiply(fr,f3);
fgm=immultiply(fg,f3);
fgb=immultiply(fb,f3);
background=cat(3,frm,fgm,fgb);
imwrite(background,'d:\bkdrabit.jpg','jpg');
figure,imshow(f),figure,imshow(background);
fore=imread('d:\forerabit.jpg');
bkd=imread('d:\bkdrabit.jpg');
out=imdivide(bkd,fore);
edge1=edge(rgb2gray(fore),'sobel');
figure,imshow(edge1);
edge2=edge(rgb2gray(bkd),'sobel');
figure,imshow(edge2);
out1=imdivide(fore,bkd);
figure,imshow(out);
figure,imshow(out1);C = xor(rgb2gray(f),f3);imshow(C);
close all
f=imread('d:\rabit.jpg');
grayrabit = rgb2gray(f);
mask = grayrabit>170;
imshow(mask);
imwrite(mask,'d:\maskrabit.jpg','jpg');
f3=imread('d:\maskrabit.jpg');
f3=im2bw(f3);
fr=f(:,:,1);
fg=f(:,:,2);
fb=f(:,:,3);
frm=immultiply(fr,f3);
fgm=immultiply(fg,f3);
fgb=immultiply(fb,f3);
foreground=cat(3,frm,fgm,fgb);
imwrite(foreground,'d:\forerabit.jpg','jpg');
figure,imshow(f),figure,imshow(foreground)
%background detection
f=imread('d:\rabit.jpg');
grayrabit = rgb2gray(f);
mask = grayrabit<170;
imshow(mask);
imwrite(mask,'d:\maskrabit.jpg','jpg');
f3=imread('d:\maskrabit.jpg');
f3=im2bw(f3);
fr=f(:,:,1);
fg=f(:,:,2);
fb=f(:,:,3);
frm=immultiply(fr,f3);
fgm=immultiply(fg,f3);
fgb=immultiply(fb,f3);
background=cat(3,frm,fgm,fgb);
imwrite(background,'d:\bkdrabit.jpg','jpg');
figure,imshow(f),figure,imshow(background);
fore=imread('d:\forerabit.jpg');
bkd=imread('d:\bkdrabit.jpg');
out=imdivide(bkd,fore);
edge1=edge(rgb2gray(fore),'sobel');
figure,imshow(edge1);
edge2=edge(rgb2gray(bkd),'sobel');
figure,imshow(edge2);
out1=imdivide(fore,bkd);
figure,imshow(out);
figure,imshow(out1);C = xor(rgb2gray(f),f3);imshow(C);
Image Processing :- Object Detection Code
f=imread('d:\rabit.jpg');
grayf = rgb2gray(f);
whiterabit= S2>180;imwrite(whiterabit,'D:\rabitthres.jpg','jpg');
fmask=imread('d:\rabitthres.jpg');
fmask=im2bw(fmask);
fr=f(:,:,1);
fg=f(:,:,2);
fb=f(:,:,3);
frm=immultiply(fr,fmask);
fgm=immultiply(fg,fmask);
fgb=immultiply(fb,fmask);
fout=cat(3,fr,fg,fgb);
background=cat(3,frm,fgm,fgb);
figure,imshow(f),figure,imshow(fout),figure,imshow(background)
Wednesday, 5 October 2016
Image Processing - Segmentation
Roipoly
>> mask3=roipoly(f);
>> r=immultiply(mask3,f(:,:,1));
>> g=immultiply(mask3,f(:,:,2));
>> b=immultiply(mask3,f(:,:,3));
>> g3=cat(3,r,g,b);
>> imshow(g3);
>> g3=rgb2gray(g3);
>> plot(g3);
---------------------------------------------------------------------
Threshold
close all
I=imread('D:\redfish.png');
imshow(I);
I1=im2double(I);
I2=mat2gray(I1);
I3=rgb2gray(I);
xx=graythresh(I);
for i= 1 : 5
bw=im2bw(I3,xx);
figure;imshow(bw);
imshow(I(:,:,1)>i & I(:,:,2)>i & I(:,:,3)>i)
end
% fthresholding by giving the range values (inbetween)
[x,map]=imread('D:\sae.png');
% s=uint8(256*ind2gray(x));
s=rgb2gray(x);
for i=10 : 200
figure,imshow(s>i & s<i+25)
end
----------------------------------------------
prog2
b=rgb2gray(a);
for i=10 : 200
figure,imshow(b>i);
% pause(5)
end
--------------------------------
[r,c,val]=find(I(:,:,1)>120)
a=I(:,:,1);
for i=1 : numel(r)
for j= 1 : numel(c)
r1=r(i);c1=c(i);
a1(r1,c1)=a(r1,c1);
end
end
imshow(a1);
-------------------------------------
function c=edgedetection(a,b)
%Edge detection
%==============
%a is a input image
%b is used to user supply a input
disp('Edge detection');
disp('1 -> Sobel');
disp('2 -> Prewitt');
disp('3 -> Roberts');
disp('4 -> Laplacian of a Gaussian');
disp('5 -> Zero crossing');
disp('6 -> Canny');
while b<=6
b=input('Enter the value :');
switch b
case 1
disp('1 -> Sobel');
a=imread('D:\h3.jpg');
s=edge(a,'sobel')
imshow(s);
case 2
disp('2 -> Prewitt');
a=imread('D:\h3.jpg');
s=edge(a,'prewitt')
imshow(s);
case 3
disp('3 -> Roberts');
a=imread('D:\h3.jpg');
s=edge(a,'Roberts')
imshow(s);
case 4
disp('4 -> Laplacian of a Gaussian');
a=imread('C:\MATLAB7\work\saranya\cameraman.tif');
s=edge(a,'LoG')
imshow(s);
case 5
disp('5 -> Zero crossing');
a=imread('D:\h3.jpg');
s=edge(a,'Zerocross')
imshow(s);
case 6
disp('6 -> Canny');
a=imread('D:\h3.jpg');
s=edge(a,'canny')
imshow(s);
otherwise
disp('Wrong input')
end
end
-----------------------------------------------------
function c=linedetection()
%Line detection
%===============
%a is a input image
%b is used to user supply a input
a=imread('D:\h3.jpg');a=a(:,:,1);
disp('Line detection');b=input('Enter the value : ');
switch b
case 1
disp('Filter a image');
a=imread('D:\kio.jpg');a=a(:,:,1);
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
imshow(g,[])
case 2
disp('Line detect to the top position');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
figure,imshow(gtop,[])
case 3
disp('Line detect to the bottom position');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
gbot=g(end-119:end,end-119:end);
%gbot=pixeldup(gbot,4);
figure,imshow(gbot,[])
case 4
disp('Line detect using absolute value');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
gbot=g(end-119:end,end-119:end);
%gbot=pixeldup(gbot,4);
g=abs(g);
figure,imshow(g,[])
case 5
disp('The point to enlarged');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
g=abs(g);
T=max(g(:));
g=g>=T;
figure,imshow(g)
otherwise
disp('Wrong input');
end
end
______________________________________________
function c=point(a,b)
%Point detection
%===============
%a is a input image
%b is used to user supply a input
disp('Point detection');
while b<=3
b=input('Enter the value : ');
switch b
case 1
a=imread('D:\fff.tif');
w=[0 0 0;1 1 1;0 1 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
case 2
a=imread('D:\mm.tif');
w=[1 1 1;1 1 1;0 0 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
case 3
a=imread('D:\RUG2.tif');
w=[0 0 0;1 0 1;0 0 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
otherwise
disp('Wrong input');
end
end
-------------------------------------------------
function f=mat(f)
f=imread('D:\moon.tif');
c=mat2huff(f);
cr1=imratio(f,c);
end
-------------------------------
I=imread('D:\redfish.png');
imshow(I);
I1=im2double(I);
I2=mat2gray(I1);
I3=rgb2gray(I);
xx=graythresh(I);
for i= 1 : 5
bw=im2bw(I3,xx);
figure;imshow(bw);
imshow(I(:,:,1)>i & I(:,:,2)>i & I(:,:,3)>i)
end
% fthresholding by giving the range values (inbetween)
[x,map]=imread('D:\sae.png');
% s=uint8(256*ind2gray(x));
s=rgb2gray(x);
for i=10 : 200
figure,imshow(s>i & s<i+25)
end
----------------------------------------------
prog2
b=rgb2gray(a);
for i=10 : 200
figure,imshow(b>i);
% pause(5)
end
--------------------------------
[r,c,val]=find(I(:,:,1)>120)
a=I(:,:,1);
for i=1 : numel(r)
for j= 1 : numel(c)
r1=r(i);c1=c(i);
a1(r1,c1)=a(r1,c1);
end
end
imshow(a1);
-------------------------------------
function c=edgedetection(a,b)
%Edge detection
%==============
%a is a input image
%b is used to user supply a input
disp('Edge detection');
disp('1 -> Sobel');
disp('2 -> Prewitt');
disp('3 -> Roberts');
disp('4 -> Laplacian of a Gaussian');
disp('5 -> Zero crossing');
disp('6 -> Canny');
while b<=6
b=input('Enter the value :');
switch b
case 1
disp('1 -> Sobel');
a=imread('D:\h3.jpg');
s=edge(a,'sobel')
imshow(s);
case 2
disp('2 -> Prewitt');
a=imread('D:\h3.jpg');
s=edge(a,'prewitt')
imshow(s);
case 3
disp('3 -> Roberts');
a=imread('D:\h3.jpg');
s=edge(a,'Roberts')
imshow(s);
case 4
disp('4 -> Laplacian of a Gaussian');
a=imread('C:\MATLAB7\work\saranya\cameraman.tif');
s=edge(a,'LoG')
imshow(s);
case 5
disp('5 -> Zero crossing');
a=imread('D:\h3.jpg');
s=edge(a,'Zerocross')
imshow(s);
case 6
disp('6 -> Canny');
a=imread('D:\h3.jpg');
s=edge(a,'canny')
imshow(s);
otherwise
disp('Wrong input')
end
end
-----------------------------------------------------
function c=linedetection()
%Line detection
%===============
%a is a input image
%b is used to user supply a input
a=imread('D:\h3.jpg');a=a(:,:,1);
disp('Line detection');b=input('Enter the value : ');
switch b
case 1
disp('Filter a image');
a=imread('D:\kio.jpg');a=a(:,:,1);
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
imshow(g,[])
case 2
disp('Line detect to the top position');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
figure,imshow(gtop,[])
case 3
disp('Line detect to the bottom position');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
gbot=g(end-119:end,end-119:end);
%gbot=pixeldup(gbot,4);
figure,imshow(gbot,[])
case 4
disp('Line detect using absolute value');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
gtop=g(1:120,1:120);
%gtop=pixeldup(gtop,4);
gbot=g(end-119:end,end-119:end);
%gbot=pixeldup(gbot,4);
g=abs(g);
figure,imshow(g,[])
case 5
disp('The point to enlarged');
w=[2 -1 -1;-1 2 -1;-1 -1 2];
g=imfilter(double(a),w);
g=abs(g);
T=max(g(:));
g=g>=T;
figure,imshow(g)
otherwise
disp('Wrong input');
end
end
______________________________________________
function c=point(a,b)
%Point detection
%===============
%a is a input image
%b is used to user supply a input
disp('Point detection');
while b<=3
b=input('Enter the value : ');
switch b
case 1
a=imread('D:\fff.tif');
w=[0 0 0;1 1 1;0 1 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
case 2
a=imread('D:\mm.tif');
w=[1 1 1;1 1 1;0 0 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
case 3
a=imread('D:\RUG2.tif');
w=[0 0 0;1 0 1;0 0 0];
g=abs(imfilter(double(a),w));
T=max(g(:));
g=g>=T;
imshow(a),figure,imshow(g)
otherwise
disp('Wrong input');
end
end
-------------------------------------------------
function f=mat(f)
f=imread('D:\moon.tif');
c=mat2huff(f);
cr1=imratio(f,c);
end
-------------------------------
Java Database Code for MS Acess using ODBC ( Sys DN) with navigation and manipulation
import java.io.*;
import java.util.*;
import java.sql.*;
public class dbpg4
{
public static int rno;
public static void main(String[] args) {
Connection con;
Statement st;
BufferedReader bufin;
ResultSet rs,rs1;
ResultSetMetaData rm;
String namef;
int numf,mark1f,mark2f,totalf,insch,pickch,numoffields,mark11f,mark22f;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:chan2");
con.setAutoCommit(false);
st = con.createStatement();
bufin = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner = new Scanner(System. in);
//String input = scanner. nextLine();
System.out.println("Pick your option");
System.out.println("-----------------");
System.out.println("1. New Record Entry");
System.out.println("2. Students Information Display");
System.out.println("3. Information Modification for a Student");
System.out.println("4. Total Mark calculation for all Students");
System.out.println("5. Grade A Students Records Deletion ");
System.out.println("6. Enquiry of a student ");
System.out.println("any other No FOR RECORD NAVIGATION");
pickch = Integer.parseInt(bufin.readLine());
switch(pickch)
{
case 1:
do
{
System.out.println("Enter Name");
namef = scanner. nextLine();
System.out.println("Enter Reg.No");
numf = Integer.parseInt(bufin.readLine());
System.out.println("Enter Mark1");
mark1f= Integer.parseInt(bufin.readLine());
System.out.println("Enter Mark2");
mark2f= Integer.parseInt(bufin.readLine());
st.execute("insert into table1(sname,sno,mark1,mark2) values('"+namef+"',"+numf+","+mark1f+","+mark2f+")");
System.out.println("Data Entry Done");
System.out.println(" do you want to Continue Insertion of records ? press no 0 to exit");
insch = Integer.parseInt(bufin.readLine());
}while(insch>0);
break;
case 2:
rs = st.executeQuery("select * from table1");
if(rs!=null)
{
rm = rs.getMetaData();
numoffields = rm.getColumnCount();
for(int i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t\t");
}
System.out.println();
while(rs.next())
{
for(int i=1; i<=numoffields; i++)
{
System.out.print(rs.getString(i) +"\t\t");
}
System.out.println();
}
}
else
System.out.println("No Record Details Available - Do Data Entry ");
break;
case 3:
System.out.println("Enter Reg.No. for changing the contents:");
numf = Integer.parseInt(bufin.readLine());
rs1=st.executeQuery("select * from table1 where sno="+numf);
rs1.next();// to set resultset pointer
System.out.println("if u want to change the name then give the name else type N");
namef = scanner.nextLine();
System.out.println("if u want to change mark1 value then give the the value else enter 0");
mark11f = scanner.nextInt();
System.out.println("if u want to change mark2 value then give the the value else enter 0");
mark22f = scanner.nextInt();
if (namef.equalsIgnoreCase("N"))
{
namef=rs1.getString("sname");
}
if (mark11f==0)
{
mark11f=Integer.parseInt(rs1.getString("mark1"));
}
if (mark22f==0)
{
mark22f=Integer.parseInt(rs1.getString("mark2"));
}
System.out.println(namef);
System.out.println(mark11f);
System.out.println(mark22f);
st.executeUpdate("update table1 set sname='"+namef+"', mark1="+mark11f+", mark2="+mark22f+" , tot=mark1+mark2 where sno="+numf);
con.setAutoCommit(true);
System.out.println(" Record Modified with your selective values");
//*{
//System.out.println("Enter Name");
// namef = scanner. nextLine();
// System.out.println("Enter Reg.No");
// numf = scanner.nextInt();
// System.out.println("Enter Mark1");
// mark11f= Integer.parseInt(bufin.readLine());
// System.out.println("Enter Mark2");
// mark22f= Integer.parseInt(bufin.readLine());
// st.executeUpdate("update table1 set sname='"+namef+"', mark1="+mark11f+", mark2="+mark22f+" , tot=mark1+mark2 where sno="+numf);
// con.setAutoCommit(true);
//System.out.println(" Record Modified");
//}
break;
case 4:
int i=st.executeUpdate("update table1 set tot=mark1+mark2");
con.setAutoCommit(true);
if(i != 0)
{
System.out.println("Records updated"+i);
}
else
{
System.out.println("No updation occured");
}
break;
case 5:
//System.out.println("Enter Reg.No to delete");
// numf = Integer.parseInt(bufin.readLine());
//int i1=st.executeUpdate("delete from table1 where sno=2");
int i1=st.executeUpdate("delete from table1 where (mark1+mark2)/2<60");
con.setAutoCommit(true);
if(i1 != 0)
{
System.out.println("No. of records deleted = "+i1);
}
else
{
System.out.println("Record Deletion not occured ");
}
break;
case 6:
System.out.println("Enter the Reg.No. to search :");
numf = Integer.parseInt(bufin.readLine());
rs1=st.executeQuery("select * from table1 where sno="+numf);
rs1.next();
rno=rs1.getRow();
namef=rs1.getString("sname");
int snumf=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
int totf=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf);
System.out.println("\tPERCENTAGE\t\t:\t"+(mark11f+mark22f)/2);
break;
default:
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs1 = st.executeQuery("select * from table1");
rm = rs1.getMetaData();
numoffields = rm.getColumnCount();
do
{
System.out.println("NAVIGATION AMONG RECORDS \n");
System.out.println(" F. Move First Record");
System.out.println(" L. Move Last Record");
System.out.println(" P. Move Previous Record");
System.out.println(" N. Move Next Record");
System.out.println(" S. Move Specific Record");
System.out.println(" n. Move single Next Record");
System.out.println(" p. Move single Previous Record");
System.out.println("PRESS F/L/P/N/S/p/n");
String nach =bufin.readLine();
switch(nach)
{
case "F":
System.out.println("FIRSRT RECORD");
rs1.first();
namef=rs1.getString("sname");
int snumf1=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
int totf1=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf1);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf1);
rs1.beforeFirst();
break;
case "L":System.out.println("LAST RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
System.out.println();
rs1.last();
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println(); rs1.afterLast();break;
case "N":System.out.println("NEXT RECORD");
while(rs1.next())
{
namef=rs1.getString("sname");
snumf1=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
totf1=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf1);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf1);
System.out.println();
}
break;
case "S":System.out.println("Which Record No is Specific one");
rno= scanner.nextInt();
rs1.absolute(rno);
System.out.println("NEEDED RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();break;
case "n" :
try
{
rs1.next();
rno=rs1.getRow();
//rs1.absolute(rno);
System.out.println(rno);
System.out.println("Single NEXT RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
catch(Exception e)
{
System.out.println("Reason : This is the Last Record :");
rs1.last();
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
break;
case "p":
try
{
rs1.previous();
rno=rs1.getRow();
System.out.println(rno);
//rs1.absolute(rno-1);
System.out.println("Single PREVIOUS RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
catch(Exception e)
{
System.out.println("Reason : This is the First Record :");
rs1.first(); for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
break;
default:bufin.close();
con.close();
System.exit(0);break;
}
System.out.println(" do you want to Continue navigation ? press no 0 to exit");
insch = Integer.parseInt(bufin.readLine());
}while(insch>0);
break;
}
}
catch(Exception e)
{
System.out.println("Error :"+e.getMessage());
}
}
}
// Statement s=con.createStatement(RecordSet.Type_SCROLL_SENSITIVE,ResultSet.ConCUR_UPDATABLE/CONCUR_READ_ONLY));
// import java.ResultSet
//set path = C:\Program Files\Java\jdk1.7.0_51\bin
//javac
import java.util.*;
import java.sql.*;
public class dbpg4
{
public static int rno;
public static void main(String[] args) {
Connection con;
Statement st;
BufferedReader bufin;
ResultSet rs,rs1;
ResultSetMetaData rm;
String namef;
int numf,mark1f,mark2f,totalf,insch,pickch,numoffields,mark11f,mark22f;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:chan2");
con.setAutoCommit(false);
st = con.createStatement();
bufin = new BufferedReader(new InputStreamReader(System.in));
Scanner scanner = new Scanner(System. in);
//String input = scanner. nextLine();
System.out.println("Pick your option");
System.out.println("-----------------");
System.out.println("1. New Record Entry");
System.out.println("2. Students Information Display");
System.out.println("3. Information Modification for a Student");
System.out.println("4. Total Mark calculation for all Students");
System.out.println("5. Grade A Students Records Deletion ");
System.out.println("6. Enquiry of a student ");
System.out.println("any other No FOR RECORD NAVIGATION");
pickch = Integer.parseInt(bufin.readLine());
switch(pickch)
{
case 1:
do
{
System.out.println("Enter Name");
namef = scanner. nextLine();
System.out.println("Enter Reg.No");
numf = Integer.parseInt(bufin.readLine());
System.out.println("Enter Mark1");
mark1f= Integer.parseInt(bufin.readLine());
System.out.println("Enter Mark2");
mark2f= Integer.parseInt(bufin.readLine());
st.execute("insert into table1(sname,sno,mark1,mark2) values('"+namef+"',"+numf+","+mark1f+","+mark2f+")");
System.out.println("Data Entry Done");
System.out.println(" do you want to Continue Insertion of records ? press no 0 to exit");
insch = Integer.parseInt(bufin.readLine());
}while(insch>0);
break;
case 2:
rs = st.executeQuery("select * from table1");
if(rs!=null)
{
rm = rs.getMetaData();
numoffields = rm.getColumnCount();
for(int i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t\t");
}
System.out.println();
while(rs.next())
{
for(int i=1; i<=numoffields; i++)
{
System.out.print(rs.getString(i) +"\t\t");
}
System.out.println();
}
}
else
System.out.println("No Record Details Available - Do Data Entry ");
break;
case 3:
System.out.println("Enter Reg.No. for changing the contents:");
numf = Integer.parseInt(bufin.readLine());
rs1=st.executeQuery("select * from table1 where sno="+numf);
rs1.next();// to set resultset pointer
System.out.println("if u want to change the name then give the name else type N");
namef = scanner.nextLine();
System.out.println("if u want to change mark1 value then give the the value else enter 0");
mark11f = scanner.nextInt();
System.out.println("if u want to change mark2 value then give the the value else enter 0");
mark22f = scanner.nextInt();
if (namef.equalsIgnoreCase("N"))
{
namef=rs1.getString("sname");
}
if (mark11f==0)
{
mark11f=Integer.parseInt(rs1.getString("mark1"));
}
if (mark22f==0)
{
mark22f=Integer.parseInt(rs1.getString("mark2"));
}
System.out.println(namef);
System.out.println(mark11f);
System.out.println(mark22f);
st.executeUpdate("update table1 set sname='"+namef+"', mark1="+mark11f+", mark2="+mark22f+" , tot=mark1+mark2 where sno="+numf);
con.setAutoCommit(true);
System.out.println(" Record Modified with your selective values");
//*{
//System.out.println("Enter Name");
// namef = scanner. nextLine();
// System.out.println("Enter Reg.No");
// numf = scanner.nextInt();
// System.out.println("Enter Mark1");
// mark11f= Integer.parseInt(bufin.readLine());
// System.out.println("Enter Mark2");
// mark22f= Integer.parseInt(bufin.readLine());
// st.executeUpdate("update table1 set sname='"+namef+"', mark1="+mark11f+", mark2="+mark22f+" , tot=mark1+mark2 where sno="+numf);
// con.setAutoCommit(true);
//System.out.println(" Record Modified");
//}
break;
case 4:
int i=st.executeUpdate("update table1 set tot=mark1+mark2");
con.setAutoCommit(true);
if(i != 0)
{
System.out.println("Records updated"+i);
}
else
{
System.out.println("No updation occured");
}
break;
case 5:
//System.out.println("Enter Reg.No to delete");
// numf = Integer.parseInt(bufin.readLine());
//int i1=st.executeUpdate("delete from table1 where sno=2");
int i1=st.executeUpdate("delete from table1 where (mark1+mark2)/2<60");
con.setAutoCommit(true);
if(i1 != 0)
{
System.out.println("No. of records deleted = "+i1);
}
else
{
System.out.println("Record Deletion not occured ");
}
break;
case 6:
System.out.println("Enter the Reg.No. to search :");
numf = Integer.parseInt(bufin.readLine());
rs1=st.executeQuery("select * from table1 where sno="+numf);
rs1.next();
rno=rs1.getRow();
namef=rs1.getString("sname");
int snumf=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
int totf=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf);
System.out.println("\tPERCENTAGE\t\t:\t"+(mark11f+mark22f)/2);
break;
default:
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs1 = st.executeQuery("select * from table1");
rm = rs1.getMetaData();
numoffields = rm.getColumnCount();
do
{
System.out.println("NAVIGATION AMONG RECORDS \n");
System.out.println(" F. Move First Record");
System.out.println(" L. Move Last Record");
System.out.println(" P. Move Previous Record");
System.out.println(" N. Move Next Record");
System.out.println(" S. Move Specific Record");
System.out.println(" n. Move single Next Record");
System.out.println(" p. Move single Previous Record");
System.out.println("PRESS F/L/P/N/S/p/n");
String nach =bufin.readLine();
switch(nach)
{
case "F":
System.out.println("FIRSRT RECORD");
rs1.first();
namef=rs1.getString("sname");
int snumf1=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
int totf1=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf1);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf1);
rs1.beforeFirst();
break;
case "L":System.out.println("LAST RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
System.out.println();
rs1.last();
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println(); rs1.afterLast();break;
case "N":System.out.println("NEXT RECORD");
while(rs1.next())
{
namef=rs1.getString("sname");
snumf1=Integer.parseInt(rs1.getString("sno"));
mark11f=Integer.parseInt(rs1.getString("mark1"));
mark22f=Integer.parseInt(rs1.getString("mark2"));
totf1=Integer.parseInt(rs1.getString("tot"));
System.out.println("Name of the Student :\t"+namef);
System.out.println("Register No :\t\t"+snumf1);
System.out.println("\t Subject Name \t\t\tMarks Scored");
System.out.println("\t LAB I\t..JAVA PROGRAMMING\t"+mark11f);
System.out.println("\t LAB II\t..VISUAL PROGRAMMING\t"+mark22f);
System.out.println("\tTOTAL MARKS\t\t:\t"+totf1);
System.out.println();
}
break;
case "S":System.out.println("Which Record No is Specific one");
rno= scanner.nextInt();
rs1.absolute(rno);
System.out.println("NEEDED RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();break;
case "n" :
try
{
rs1.next();
rno=rs1.getRow();
//rs1.absolute(rno);
System.out.println(rno);
System.out.println("Single NEXT RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
catch(Exception e)
{
System.out.println("Reason : This is the Last Record :");
rs1.last();
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
break;
case "p":
try
{
rs1.previous();
rno=rs1.getRow();
System.out.println(rno);
//rs1.absolute(rno-1);
System.out.println("Single PREVIOUS RECORD");
for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
catch(Exception e)
{
System.out.println("Reason : This is the First Record :");
rs1.first(); for( i=1; i<=numoffields; i++)
{
System.out.print(rm.getColumnName(i)+"\t");
}
for( i=1; i<=numoffields; i++)
{
System.out.print(rs1.getString(i) +"\t");
}
System.out.println();
}
break;
default:bufin.close();
con.close();
System.exit(0);break;
}
System.out.println(" do you want to Continue navigation ? press no 0 to exit");
insch = Integer.parseInt(bufin.readLine());
}while(insch>0);
break;
}
}
catch(Exception e)
{
System.out.println("Error :"+e.getMessage());
}
}
}
// Statement s=con.createStatement(RecordSet.Type_SCROLL_SENSITIVE,ResultSet.ConCUR_UPDATABLE/CONCUR_READ_ONLY));
// import java.ResultSet
//set path = C:\Program Files\Java\jdk1.7.0_51\bin
//javac
Subscribe to:
Posts (Atom)
