0% found this document useful (0 votes)
18 views

Ads E3

The document describes an experiment involving horizontal fragmentation of data across a client and server. The client sends a SQL query to the server, which executes the query on its local database and returns the results along with the number of rows back to the client. The client then inserts the received rows into its local database table.

Uploaded by

Shreya Jadhav
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)
18 views

Ads E3

The document describes an experiment involving horizontal fragmentation of data across a client and server. The client sends a SQL query to the server, which executes the query on its local database and returns the results along with the number of rows back to the client. The client then inserts the received rows into its local database table.

Uploaded by

Shreya Jadhav
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/ 6

EXPERIMENT NO 03:

Shreya Ramchandra Jadhav Roll No: 10

## Client Side:
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class Hfc {


public static void main(String[] args) {
DataInputStream dis;
DataOutputStream dos;
InputStream is;
OutputStream os;
Statement st,st1,st2,st3;
Scanner s1=new Scanner(System.in);

try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost/fragmentation?autoReconnect=true","root","root");
st=con.createStatement();
Socket s=new Socket("127.0.0.1",1520);

is=s.getInputStream();
os=s.getOutputStream();
dis=new DataInputStream(is);
dos=new DataOutputStream(os);
System.out.println("Enter the query");
String rw=s1.nextLine();
dos.writeUTF(rw);
System.out.println("Horizontal fragmentation");

int id,sal;
String nm;
String ect;
int count=dis.readInt();

for(int i=0;i<count;i++){

id= dis.readInt();
nm=dis.readUTF();
sal= dis.readInt();
ect=dis.readUTF();
st.executeUpdate("insert into empkop
values("+id+",'"+nm+"',"+sal+",'"+ect+"')");
}

ResultSet rs1=st.executeQuery("select * from empkop ");

while(rs1.next()){
int id1=rs1.getInt(1);
nm=rs1.getString(2);
sal=rs1.getInt(3);
ect=rs1.getString(4);
System.out.println(id1+"\t"+nm+"\t"+sal+"\t"+ect);
}
}
catch(Exception e){
System.out.println(e);
}
}
}

Output:
## Server Side:
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class Hfs {

public static void main(String args[]){


DataInputStream dis;
DataOutputStream dos;
InputStream is;
OutputStream os;
Scanner s1=new Scanner(System.in);
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection
("jdbc:mysql://localhost/fragmentation?autoReconnect=true","root","root");
Statement st=con.createStatement();
ServerSocket s=new ServerSocket(1520);
Socket s2=s.accept();
is=s2.getInputStream();
os=s2.getOutputStream();
dis=new DataInputStream(is);
dos=new DataOutputStream(os);
int count=0;

String rw=new String(dis.readUTF());


System.out.println(rw);
ResultSet rs1=st.executeQuery(rw);

while (rs1.next())
{
int id=rs1.getInt(1);
String nm=rs1.getString(2);
int sal=rs1.getInt(3);
String ect=rs1.getString(4);
System.out.println(id+"\t"+nm+"\t"+sal+"\t"+ect); count++;
}
dos.writeInt(count);
String nm;
int id,sal;
String ect;
ResultSet rs2=st.executeQuery(rw);

while(rs2.next())
{
id=rs2.getInt(1);
nm=rs2.getString(2);
sal=rs2.getInt(3);
ect=rs2.getString(4);

dos.writeInt(id);
dos.writeInt(sal);
dos.writeUTF(nm);
dos.writeUTF(ect);
}
}
catch(Exception e) {
System.out.println(e);
}
}

Output:

You might also like