From b9dca294abc7fd08d7c680f74ca8d1ffaed27781 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 00:21:07 +0530 Subject: [PATCH 1/8] commit4-travellingsalesman --- TravellingSalesman.java | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 TravellingSalesman.java diff --git a/TravellingSalesman.java b/TravellingSalesman.java new file mode 100644 index 0000000..2fb1ca2 --- /dev/null +++ b/TravellingSalesman.java @@ -0,0 +1,92 @@ +import java.util.*; + +public class TravellingSalesman +{ + private int numberOfNodes; + private Stack stack; + + public TravellingSalesman() + { + stack = new Stack(); + } + + public void tsp(int adjacencyMatrix[][]) + { + numberOfNodes = adjacencyMatrix[1].length - 1; + int[] visited = new int[numberOfNodes]; + visited[0] = 1; + stack.push(0); + int element, dst = -1, i; + int min = Integer.MAX_VALUE; + boolean minFlag = false; + System.out.print(0 + "\t"); + + while (!stack.isEmpty()) + { + element = stack.peek(); + i = 1; + min = Integer.MAX_VALUE; + while (i 1 && visited[i] == 0) + { + if (min > adjacencyMatrix[element][i]) + { + min = adjacencyMatrix[element][i]; + dst = i; + minFlag = true; + } + } + i++; + } + if (minFlag) + { + visited[dst] = 1; + stack.push(dst); + System.out.print(dst + "\t"); + minFlag = false; + continue; + } + stack.pop(); + } + } + + public static void main(String... arg) + { + int number_of_nodes; + Scanner scanner = null; + try + { + System.out.println("Enter the number of nodes in the graph"); + scanner = new Scanner(System.in); + number_of_nodes = scanner.nextInt(); + int adjacency_matrix[][] = new int[number_of_nodes][number_of_nodes]; + System.out.println("Enter the adjacency matrix"); + for (int i = 0; i < number_of_nodes; i++) + { + for (int j = 0; j < number_of_nodes; j++) + { + adjacency_matrix[i][j] = scanner.nextInt(); + } + } + for (int i = 0; i < number_of_nodes; i++) + { + for (int j = 0; j < number_of_nodes; j++) + { + if (adjacency_matrix[i][j] == 1 && adjacency_matrix[j][i] == 0) + { + adjacency_matrix[j][i] = 1; + } + } + } + System.out.println("the citys are visited as follows"); + TravellingSalesman obj = new TravellingSalesman(); + obj.tsp(adjacency_matrix); + } catch (Exception E) + { + System.out.println(E); + System.out.println("Wrong Input format"); + } + scanner.close(); + } +} \ No newline at end of file From dcce83ebdd99ee441645b1d6f3d1c866a7702ed6 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 00:26:20 +0530 Subject: [PATCH 2/8] commit5-floydwarshall --- FloydWarshall.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 FloydWarshall.java diff --git a/FloydWarshall.java b/FloydWarshall.java new file mode 100644 index 0000000..ddf18da --- /dev/null +++ b/FloydWarshall.java @@ -0,0 +1,38 @@ +public class FloydWarshall { + + public static void floydWarshall(int[][] graph){ + int N = graph.length; + int dist[][] = new int[N][N]; + for(int i=0;i Date: Sun, 17 Jul 2016 00:32:50 +0530 Subject: [PATCH 3/8] Create info --- jdbc-tcp/info | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 jdbc-tcp/info diff --git a/jdbc-tcp/info b/jdbc-tcp/info new file mode 100644 index 0000000..9b085f6 --- /dev/null +++ b/jdbc-tcp/info @@ -0,0 +1,4 @@ +This project shows you how to connect your java program on a client to a java application a remote server that can serve you with database information. +A java-java communication takes place via TCP Sockets (there are other methods too), and +A java-database communication takes place via JDBC API. +So, I have designed this project to give the viewer a gist of both of these. From 32f9499196519567a2c3e362ea4f4cf74dbb2ff3 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 17:44:05 +0530 Subject: [PATCH 4/8] Update info --- jdbc-tcp/info | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jdbc-tcp/info b/jdbc-tcp/info index 9b085f6..9bfc4de 100644 --- a/jdbc-tcp/info +++ b/jdbc-tcp/info @@ -2,3 +2,6 @@ This project shows you how to connect your java program on a client to a java ap A java-java communication takes place via TCP Sockets (there are other methods too), and A java-database communication takes place via JDBC API. So, I have designed this project to give the viewer a gist of both of these. +The database that I have used contains 5 records, with the "Eid" values 1 to 5. +So, enter any one from 1 to 5 on client side, and the employee details will be fetched accordingly. +You can alter the database as per need. Happy Coding! From 1215b05a86e3da59d9e2ad0a3648d02d2af20a3f Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 17:46:02 +0530 Subject: [PATCH 5/8] Create info --- jdbc-tcp/employeedb/info | 1 + 1 file changed, 1 insertion(+) create mode 100644 jdbc-tcp/employeedb/info diff --git a/jdbc-tcp/employeedb/info b/jdbc-tcp/employeedb/info new file mode 100644 index 0000000..35c98b5 --- /dev/null +++ b/jdbc-tcp/employeedb/info @@ -0,0 +1 @@ +Employee database files. From fa56e986fd0537f5f4d0952d4c15f5010adce7f2 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 17:47:45 +0530 Subject: [PATCH 6/8] db-commit --- jdbc-tcp/employeedb/db.opt | 2 ++ jdbc-tcp/employeedb/employee.frm | Bin 0 -> 8680 bytes jdbc-tcp/employeedb/employee.ibd | Bin 0 -> 98304 bytes 3 files changed, 2 insertions(+) create mode 100644 jdbc-tcp/employeedb/db.opt create mode 100644 jdbc-tcp/employeedb/employee.frm create mode 100644 jdbc-tcp/employeedb/employee.ibd diff --git a/jdbc-tcp/employeedb/db.opt b/jdbc-tcp/employeedb/db.opt new file mode 100644 index 0000000..4ed6015 --- /dev/null +++ b/jdbc-tcp/employeedb/db.opt @@ -0,0 +1,2 @@ +default-character-set=utf8 +default-collation=utf8_general_ci diff --git a/jdbc-tcp/employeedb/employee.frm b/jdbc-tcp/employeedb/employee.frm new file mode 100644 index 0000000000000000000000000000000000000000..692c4466e0d1a2c8b2f511e2cccc6d2b96c6d6df GIT binary patch literal 8680 zcmeI&zYf7r6bA6Gb#GgLfrP3Q&Lo6rcbFC_n)U{F1=U zk)Qs5yc`*DnBgJ=1 literal 0 HcmV?d00001 diff --git a/jdbc-tcp/employeedb/employee.ibd b/jdbc-tcp/employeedb/employee.ibd new file mode 100644 index 0000000000000000000000000000000000000000..5866c6717ec27f5f9d3c0137a914f90fc2b76811 GIT binary patch literal 98304 zcmeI)J!=#}7y#h8O)e^;M6pm&I1$83#6}bgKN2B=pRrKEVmVelNY0R46uT=dL<^14 zRuKG(zad~@WosdbzrjYZjx(F&T&~cAc?|m_# z|JkqZ>z`U5WBfo`^S9c{`Fk0sb5wKt)qOhu-#Yi|zLo#QB>@5i2oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z{PO~-?myM}H@?1p5|imwSv91GRX&qt(9Fnw*^sLt%XgGqY3EMZDV-zb`Nx4yV|9S&F}SzZ>7ap*Ea;jvYTS ze)C%Ac0OG+M%&k0?V^~D^F=qz?jMekTf?Ck80zIm3Kkzck0G1O$ZTZvV@oIZ1QB=6*n@n)-NcUm)@Zm8```=yiaT{&r) z_Tt>j7`Ckp8$5UZ!o{L_qupxe6OCi-d?IchBj-|N+Hn8UhH}H9a>K{3V&wKRvVQ6E zl~ehxyfISTDkg4Dr37o=yW#!0v{EBLfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+0D=EOU@A0I-G8d{{~ywo zBLM;g2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF s5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5cr+I4+A#TWdHyG literal 0 HcmV?d00001 From 8de8d0eec1de320e32c5225d71c5706424d2d915 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 17:49:03 +0530 Subject: [PATCH 7/8] java files --- jdbc-tcp/Employee.java | 34 ++++++++++++++++++++ jdbc-tcp/TCPClient.java | 34 ++++++++++++++++++++ jdbc-tcp/TCPServer.java | 69 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 jdbc-tcp/Employee.java create mode 100644 jdbc-tcp/TCPClient.java create mode 100644 jdbc-tcp/TCPServer.java diff --git a/jdbc-tcp/Employee.java b/jdbc-tcp/Employee.java new file mode 100644 index 0000000..18d53c8 --- /dev/null +++ b/jdbc-tcp/Employee.java @@ -0,0 +1,34 @@ +public class Employee implements java.io.Serializable{ + + private static final long serialVersionUID = 1L; + + private int Eid; + private String name; + private String post; + private int Did; + private int salary; + + Employee(int Eid, String name, String post, int Did, int salary){ + this.Eid = Eid; + this.name = name; + this.post = post; + this.Did = Did; + this.salary = salary; + } + + public int getEid(){ + return this.Eid; + } + public String getName(){ + return this.name; + } + public String getPost(){ + return this.post; + } + public int getDid(){ + return this.Did; + } + public int getSalary(){ + return this.salary; + } +} diff --git a/jdbc-tcp/TCPClient.java b/jdbc-tcp/TCPClient.java new file mode 100644 index 0000000..cae98b1 --- /dev/null +++ b/jdbc-tcp/TCPClient.java @@ -0,0 +1,34 @@ +import java.io.*; +import java.net.*; + +public class TCPClient { + + public static void main(String[] args) { + String serverName = "localhost"; + int port = 6666; + try{ + System.out.println("\n\nConnecting to " + serverName + " on port " + port); + Socket client = new Socket(serverName, port); + System.out.println("\n\nJust connected to " + client.getRemoteSocketAddress()); + + System.out.print("\n\n\nEnter Employee ID : "); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int idInput = Integer.parseInt(br.readLine()); + + OutputStream outToServer = client.getOutputStream(); + DataOutputStream out = new DataOutputStream(outToServer); + out.writeInt(idInput); + + InputStream inFromServer = client.getInputStream(); + DataInputStream in = new DataInputStream(inFromServer); + System.out.print("\n\n\n\n\nBelow details were returned by the server : "+in.readUTF()); + + client.close(); + } + catch(Exception e){ + System.out.println("Client Side problem : "+e); + } + + } + +} diff --git a/jdbc-tcp/TCPServer.java b/jdbc-tcp/TCPServer.java new file mode 100644 index 0000000..58a4cbd --- /dev/null +++ b/jdbc-tcp/TCPServer.java @@ -0,0 +1,69 @@ +import java.util.*; +import java.io.*; +import java.net.*; +import java.sql.*; + +public class TCPServer { + + private ServerSocket TCPSocket; + + public TCPServer(int port)throws IOException{ + TCPSocket = new ServerSocket(port); + TCPSocket.setSoTimeout(2147483647); + } + + public void retrieveEmployee(){ + while(true) + { + try + { + System.out.println("\n\nWaiting for client on port " + TCPSocket.getLocalPort() + "..."); + Socket server = TCPSocket.accept(); + System.out.println("\n\nJust connected to "+ server.getRemoteSocketAddress()); + DataInputStream in = new DataInputStream(server.getInputStream()); + int x = in.readInt(); + System.out.println("\n\nClient Requested for employee "+x); + + Class.forName("com.mysql.jdbc.Driver"); + Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/EmployeeDB","root", "pass"); + PreparedStatement stmt=con.prepareStatement("SELECT *FROM EMPLOYEE WHERE Eid = ?"); + stmt.setInt(1,x); + List details = new ArrayList(); + ResultSet rs = stmt.executeQuery(); + while(rs.next()){ + Employee E = new Employee(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getInt(4),rs.getInt(5)); + details.add(E); + } + String str = null; + for(Employee E : details){ + str = "\n\n\nEMPLOYEE ID : "+Integer.toString(E.getEid())+"\nEMPLOYEE NAME : "+E.getName()+"\nPOST : "+E.getPost()+"\nDEPT ID : "+Integer.toString(E.getDid()) + +"\nSALARY : "+Integer.toString(E.getSalary())+"\n\n\n"; + } + + DataOutputStream out = new DataOutputStream(server.getOutputStream()); + out.writeUTF(str); + + server.close(); + + + } + catch(Exception e){ + System.out.println("Server side Retrieval problem : "); + e.printStackTrace(); + } + } + } + + public static void main(String[] args) { + int port = 6666; + try{ + TCPServer t = new TCPServer(port); + t.retrieveEmployee(); + + }catch(Exception e){ + System.out.println("Server main method problem : "+e); + } + + } + +} From c13106ba6bc7eb68eedc42baf49196416183e627 Mon Sep 17 00:00:00 2001 From: Vatsal Gosaliya Date: Sun, 17 Jul 2016 17:49:56 +0530 Subject: [PATCH 8/8] sql-script-commit --- jdbc-tcp/employeedb/EmployeeDB.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 jdbc-tcp/employeedb/EmployeeDB.sql diff --git a/jdbc-tcp/employeedb/EmployeeDB.sql b/jdbc-tcp/employeedb/EmployeeDB.sql new file mode 100644 index 0000000..b0832c4 --- /dev/null +++ b/jdbc-tcp/employeedb/EmployeeDB.sql @@ -0,0 +1,13 @@ +CREATE TABLE Employee( +Eid INT NOT NULL, +name VARCHAR(20) NOT NULL, +post VARCHAR(20) NOT NULL, +Did INT NOT NULL, +salary INT NOT NULL +); + +INSERT INTO Employee (Eid, name, post, Did, salary) VALUES (1, 'ABC', 'Software Engineer', 101, 40000); +INSERT INTO Employee (Eid, name, post, Did, salary) VALUES (2, 'DEF', 'Systems Engineer', 201, 25000); +INSERT INTO Employee (Eid, name, post, Did, salary) VALUES (3, 'MNO', 'Data Scientist', 302, 30000); +INSERT INTO Employee (Eid, name, post, Did, salary) VALUES (4, 'PQR', 'Technical Analyst', 401, 30000); +INSERT INTO Employee (Eid, name, post, Did, salary) VALUES (5, 'XYZ', 'Java Developer', 501, 50000); \ No newline at end of file