Connect Java Program to mysql database

step 1: create mysql Database and tables

create database studinfo;

use studinfo;

create table stud(id int(10), name varchar(20), dept varchar(20), phn int(12));

step 2: create java program

javaconnectivity
Step 3: To Execute this program you require mysql connector

Download from here….
mysql Connector

Step 4: Configure Eclipse

1.1 Start Eclipse ->  File -> New Project -> Give any name to project -> finish

CreateProject

1.2 right click on your project in package explorer ->new-> class-> give class name and optional package name

newclass

Note: your Class name should always start with “Uppercase letter”.

1.3 copy following code and and Paste in your java class created above

package studinfo;

import java.sql.*;
class StudInfoDatabaseConnection
{
public static void main(String args[]){
try{
Class.forName(“com.mysql.jdbc.Driver”);
Connection con=DriverManager.getConnection
( “jdbc:mysql://localhost:3306/studinfo”,”root”,”root”);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(“select * from stud”);
while(rs.next())
System.out.println (rs.getInt(1)+” “+rs.getString(2)+” “+rs.getString(3)+ ” ” + rs.getInt(4));
con.close();
}
catch(Exception e){ System.out.println(e);
}
}

1.4 right click ->your project in package explorer ->Buid path -> Configure Build path -> libraries

buidpath

Select your mysql connector Downloded in step 3 above -> Click ok -> Run Project.

Advertisements

SDL Lab Assignments

Data Structures in java

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
import java.util.Vector;

 

public class DataStructures {

enum Days //to define fixed set of constants static and final
{
Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday;

}
public static void main(String[] args) throws IOException
{
Enumeration days; //to iterate elements in a collection of objects
Vector dayNames = new Vector();
dayNames.add(“Sunday”);
dayNames.add(“Monday”);
dayNames.add(“Tuesday”);
dayNames.add(“Wednesday”);
dayNames.add(“Thursday”);
dayNames.add(“Friday”);
dayNames.add(“Saturday”);
days = dayNames.elements();

while(days.hasMoreElements())
{
System.out.println(days.nextElement());
}

Days day=Days.Monday;

switch(day)
{
case Sunday :
System.out.println(“sunday”);
break;
case Monday :
System.out.println(“monday”);
break;
}

//bit set special type of array that holds bit values can increase in size as needed.

BitSet bits1 = new BitSet();
BitSet bits2 = new BitSet();

for(int i=1;i<=10;i++)
{
if(i%2==0)
bits1.set(i);
else
bits2.set(i);
}

System.out.println(bits1);
System.out.println(bits2);

//and op
System.out.print(“bits and”);
bits2.and(bits1);
System.out.println(bits2);

//or op
System.out.print(“bits or”);
bits2.or(bits1);
System.out.println(bits2);

//vactor
dynamic array
Vector<String> v=new Vector<>();
v.add(“hi”);
v.add(“hello”);
v.add(“ok”);

for(String s:v)
{
System.out.println(s);
}

//stack

Stack st=new Stack();
st.push(“hi”);
st.push(“hello”);
st.push(“bye”);

System.out.println(st.pop());
System.out.println(st);

//dictionary

//key value
Dictionary d = new Hashtable();
d.put(1, “sunday”);
d.put(2, “monday”);
d.put(3, “tuesday”);
d.put(4, “wednesday”);
d.put(5, “thursday”);
d.put(6, “friday”);
d.put(7, “saturday”);

for(int i=1;i<d.size();i++)
{
System.out.println(d.get(i));
}

Enumeration e1 = d.keys();
Enumeration e2 = d.elements();
while(e1.hasMoreElements())
{
System.out.println(e1.nextElement());
}
while(e2.hasMoreElements())
{
System.out.println(e2.nextElement());
}
//dictionary -> HashTable ->Properties

//properties key value both strings

Properties capitals = new Properties();
capitals.put(“India”, “Delhi”);
capitals.put(“United States”, “Washington D.C.”);
capitals.put(“United Kingdom”, “London”);
capitals.put(“Japan”, “Tokyo”);
capitals.put(“Thailand”, “Bangkok”);
capitals.put(“France”, “Paris”);
capitals.put(“Germany”, “Berlin”);

Set keys=capitals.keySet();
Iterator itr = keys.iterator();

while(itr.hasNext()) {
String str = (String) itr.next();
System.out.println(“The capital of ” + str + ” is ” +
capitals.getProperty(str) + “.”);
}

capitals.store(new FileWriter(“info.properties”),”Properties Example”);

FileReader reader=new FileReader(“info.properties”);

Properties p=new Properties();
p.load(reader);

System.out.println(p.getProperty(“India”));
System.out.println(p.getProperty(“United States”));
}
}

Computer Network Lab Assignment List

1 Lab Assignment on Unit I: (Mandatory Assignment)

Part A: Setup a wired LAN using Layer 2 Switch and then IP switch of minimum four computers. It includes preparation of cable, testing of cable using line tester, configuration machine using IP addresses, testing using PING utility and demonstrate the PING packets captured traces using Wireshark Packet Analyzer Tool.

Part B: Extend the same Assignment for Wireless using Access Point

2

Write a program for error detection and correction for 7/8 bits ASCII codes using Hamming Codes or CRC. Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.( 50% students will perform Hamming Code and others will perform CRC)

3

Write a program to simulate Go back N and Selective Repeat Modes of Sliding Window Protocol in peer to peer mode and demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

4

Write a program to simulate the behavior of link state routing protocol to find suitable path for transmission.

5 Write a program to demonstrate subletting and find the subnet masks.
6 Lab Assignment on Unit V: (Mandatory Assignment) (Use C/C++)

Write a program using TCP socket for wired network for following

a. Say Hello to Each other ( For all students)

b. File transfer ( For all students)

c. Calculator (Arithmetic) (50% students)

d. Calculator (Trigonometry) (50% students)

Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

7 Lab Assignment on Unit V: (Mandatory Assignment) (Use C/C++)

Write a program using UDP Sockets to enable file transfer (Script, Text, Audio and Video one file each) between two machines. Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

8 Lab Assignment on Unit V: (Mandatory Assignment) (Use C/C++)

Write a program to analyze following packet formats captured through Wireshark for wired network. 1. Ethernet 2. IP 3.TCP 4. UDP

9 Lab Assignment on Unit VI: (Use JAVA/PYTHON)

Write a program for DNS lookup. Given an IP address input, it should return URL and vice-versa.

10

Installing and configure DHCP server and write a program to install the software on remote machine.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

GROUP B
9 Lab Assignment on Unit IV and Unit V: (Mandatory Assignment)

Use network simulator NS2 to implement:

a. Monitoring traffic for the given topology

b. Analysis of CSMA and Ethernet protocols

c. Network Routing: Shortest path routing, AODV.

d. Analysis of congestion control (TCP and UDP).

10 Configure RIP/OSPF/BGP using packet Tracer
11 Write a program using UDP sockets for wired network to implement

a. Peer to Peer Chat

b. Multiuser Chat

Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

12 Write a program using TCP sockets for wired network to implement

a. Peer to Peer Chat

b. Multiuser Chat

Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                  Prof A. S. Patil                                                           Prof N. R. Wankhade      

               ( Subject In charge)                                                                  (HOD)

 

 

                   Prof A. S. Patil

                (Subject In charge)

CNL Lab Assignment based on Socket Programming

Write a program using TCP socket for wired network for following
a. Say Hello to Each other ( For all students)
b. File transfer ( For all students)
c. Calculator (Arithmetic) (50% students)
d. Calculator (Trigonometry) (50% students)
Demonstrate the packets captured traces using Wireshark Packet Analyzer Tool for peer to peer mode.

part a :

Server Program:

/****************** SERVER CODE ****************/

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main(){
int welcomeSocket, newSocket;
char buffer[1024];
struct sockaddr_in serverAddr;
struct sockaddr_storage serverStorage;
socklen_t addr_size;

/*—- Create the socket. The three arguments are: —-*/
/* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);

/*—- Configure settings of the server address struct —-*/
/* Address family = Internet */
serverAddr.sin_family = AF_INET;
/* Set port number, using htons function to use proper byte order */
serverAddr.sin_port = htons(7891);
/* Set IP address to localhost */
serverAddr.sin_addr.s_addr = inet_addr(“127.0.0.1”);
/* Set all bits of the padding field to 0 */
memset(serverAddr.sin_zero, ‘\0’, sizeof serverAddr.sin_zero);

/*—- Bind the address struct to the socket —-*/
bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));

/*—- Listen on the socket, with 5 max connection requests queued —-*/
if(listen(welcomeSocket,5)==0)
printf(“Listening\n”);
else
printf(“Error\n”);

/*—- Accept call creates a new socket for the incoming connection —-*/
addr_size = sizeof serverStorage;
newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size);

/*—- Send message to the socket of the incoming connection —-*/
strcpy(buffer,”Hello World\n”);
send(newSocket,buffer,13,0);

return 0;
}

Client Program:

/****************** CLIENT CODE ****************/

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main(){
int clientSocket;
char buffer[1024];
struct sockaddr_in serverAddr;
socklen_t addr_size;

/*—- Create the socket. The three arguments are: —-*/
/* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
clientSocket = socket(PF_INET, SOCK_STREAM, 0);

/*—- Configure settings of the server address struct —-*/
/* Address family = Internet */
serverAddr.sin_family = AF_INET;
/* Set port number, using htons function to use proper byte order */
serverAddr.sin_port = htons(7891);
/* Set IP address to localhost */
serverAddr.sin_addr.s_addr = inet_addr(“127.0.0.1”);
/* Set all bits of the padding field to 0 */
memset(serverAddr.sin_zero, ‘\0’, sizeof serverAddr.sin_zero);

/*—- Connect the socket to the server using the address struct —-*/
addr_size = sizeof serverAddr;
connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size);

/*—- Read the message from the server into the buffer —-*/
recv(clientSocket, buffer, 1024, 0);

/*—- Print the received message —-*/
printf(“Data received: %s”,buffer);

return 0;
}

Disjunctive Normal form (DNF)

what is DNF?

In a logical expression, a product of the variable and their negation is called elementary product.

e.g p^q, ~p^~q, ~p^q are elementary product

A sum of the variable and their negation is called elementary sum

e.g p v q, ~p v~q, ~p v q

Definition:

A logical expression is said to be in DNF form is it is the sum of elementary product.

dnf