Professional Documents
Culture Documents
Enterprise Computing With Java Lab File BCE - C - 651: Submitted By: Submitted To
Enterprise Computing With Java Lab File BCE - C - 651: Submitted By: Submitted To
JAVA LAB
FILE
BCE – C –651
This is to certify that the programs in this file are compiled and executed
by me, and I have not copied them from anywhere. This work is done by
Aayush Verma
Exam no. – 186301004
Class Rollno. – 04
Certificate by Teacher
This is to certify that the programs in this file are done under my
Assistant Professor
Department of Computer Science & Engineering
Faculty of Engineering and Technology
PROGRAM:
/*
*/
import java.sql. *;
class Example2
{
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static String DB_URL = "jdbc:mysql://localhost:3306/";
System.out.println("Creating database...");
Statement stmt = con.createStatement();
//selection Database
DB_URL+="STUDENTS";
con = DriverManager.getConnection(DB_URL,"namit","namit");
//CREATING TABLE
System.out.println("Creating table in given database...");
stmt = con.createStatement();
stmt.executeUpdate(query);
AAYUSH VERMA ROLL NO.:186301004 B.TECH CSE 6th SEMESTER
System.out.println("Created table in given database...");
//INSERTING RECORDS
System.out.println("Inserting records into the table...");
//stmt = conn.createStatement();
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
rs.close();
AAYUSH VERMA ROLL NO.:186301004 B.TECH CSE 6th SEMESTER
Thread.sleep(1000);
//UPDATING ROWS
System.out.println("Updating Registration table for id 100 and
101.....");
String change = "UPDATE Registration " + "SET age = 30 WHERE id in
(100, 101)";
stmt.executeUpdate(change);
System.out.println("Records Updated...");
// Now you can extract all the records
// to see the updated records
System.out.println("Executing select query to check the updates...");
Thread.sleep(1000);
show = "SELECT id, first, last, age FROM Registration";
rs = stmt.executeQuery(show);
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
//DELETING ROW
System.out.println("Deleting row for id =101.....");
Thread.sleep(1000);
String del = "DELETE FROM Registration " + "WHERE id = 101";
stmt.executeUpdate(del);
System.out.println("Record Deleted....");
while(rs.next()){
//Retrieve by column name
int id = rs.getInt("id");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");
}catch(Exception e){System.out.println(e);}
}
}
PROGRAM:
import java.sql.*;
class DBprepareSt{
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/STUDE
NTS","root","root");
st.setInt(1,107);
st.setString(2,"Rahul");
st.setString(3,"Sharma");
st.setInt(4,24);
st.executeUpdate();
System.out.println("Data Inserted.");
ResultSet rs=st.executeQuery(query);
while(rs.next()){
con.close();
}catch(Exception e){System.out.println(e);}
OUTPUT:
PROGRAM:
next: Moves the cursor forward one row. Returns true if the cursor is now
positioned on a row and false if the cursor is positioned after the last
row.
previous: Moves the cursor backward one row. Returns true if the cursor
is now positioned on a row and false if the cursor is positioned before
the first row.
first: Moves the cursor to the first row in the ResultSet object. Returns
true if the cursor is now positioned on the first row and false if the
ResultSet object does not contain any rows.
last:: Moves the cursor to the last row in the ResultSet object. Returns
true if the cursor is now positioned on the last row and false if the
ResultSet object does not contain any rows.
afterLast: Positions the cursor at the end of the ResultSet object, after
the last row. If the ResultSet object does not contain any rows, this
method has no effect.
*/
Connection con =
DriverManager.getConnection(DB_URL,"namit","namit");
Statement stmt = con.createStatement();
//MOVING THROUGH THE RESULTSET
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultS
et.CONCUR_READ_ONLY);
String sel = "SELECT id, first, last, age FROM Registration";
ResultSet rs = stmt.executeQuery(sel);
rs.close();
//DROPING DATABASE
System.out.println("Deleting database...");
con.close();
}catch(Exception e){System.out.println(e);}
}
}
OUTPUT:
PROGRAM:
import java.rmi.*;
import java.rmi.*;
import java.rmi.server.*;
AdderRemote()throws RemoteException{
super();
3) create the stub and skeleton objects using the rmic tool.
rmic AdderRemote
rmiregistry 5000
import java.rmi.*;
import java.rmi.registry.*;
try{
Naming.rebind(“rmi://localhost:3000/aayush”,stub);
}catch(Exception e){System.out.println(e);}
import java.rmi.*;
try{
Adder stub=(Adder)Naming.lookup(“rmi://localhost:3000/aayush”);
System.out.println(stub.add(34,4));
}catch(Exception e){}
PROGRAM:
//Server.java
import java.io.*;
import java.net.*;
try{
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
//Client.java
import java.io.*;
import java.net.*;
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
OUTPUT: