Sie sind auf Seite 1von 25

LAB EXPERIMENT 1

Objective: Create the following Java Project using IBM RAD 8.5
P1. You are required to go through RAD Environment & try to understand its
utility then write down following:
a. Shortcut commands(As many as possible)

S. No.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.

Shortcuts
Ctrl+Shift+r
Ctrl+o
Ctrl+F4
Ctrl+Shift+F4
Ctrl+f
Ctrl+k
Ctrl+Shift+k
Ctrl+l
Ctrl+h
Ctrl+F8
Ctrl+M
Ctrl+Shift+s
Ctrl+Shift+f
Ctrl+Shift+o
Ctrl+Shift+p
F3
F6

18.

F8

19.
20.
21.
22.
23.

Ctrl+Space
Ctrl+b
Ctrl+/
Ctrl+Shift+/
Ctrl+T

Description
Helps to choose a resource
List all methods in a class in java file
Close active file in RAD editor
Close all open windows in editor
Helps to find/replace phrase in a file
Helps to find the next searched phrase
Find the previous searched phrase
Helps to go to particular line number
Find file/phrase etc. in a workspace
Switch to available editors
Maximize active view or editor
Save all
Format code
Organize imports
Show matching brace
Show source for a method/class
In debug mode, for step into to debug
by executing each and every line
In debug mode, for step into to debug
for every breakpoint
Content assist
Build all
Single line comment
Multi line comment
Open implementation

b. What are views?


Views provide different presentations of resources or ways of navigating through
the information in your workspace.
c. What are Perspective?
Perspective provides a convenient grouping of views and editors that match a
particular way of using RAD.
P2. WAP to input the distance in feet and inches, then display the distance in feet
and inches (more than 12 inches should be converted into feet) by using classes
and objects.
package R110212055.Saurabh.Q2;
import java.util.Scanner;
public class Convert
{
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
float d1,d2,d3=0,d4=0;
System.out.println("You have to enter the distance in feet and
inches like 'x' feet and 'y' inches\n");
Scanner sc = new Scanner (System.in);
System.out.println("Enter The Distance in Feet(x): ");
d1=sc.nextFloat();
System.out.println("Enter The Distance in Inches(y): ");
d2=sc.nextFloat();
if(d2>=12.0)
{
d3=d2-12;
d4=1+(d3/12);

System.out.println("The Total Distance is "+(d1+d4)+"


Feet");
}
else
{
System.out.println("The Total Distance is "+d1+" Feet
and "+d2+" Inches");
}
}
}

P3. Write a program to read students details like id , name and marks of 3 subjects
and find out how many students are passed / failed [pass marks =50 @ in each
subject] and display the student details in ascending order based total. Take the
input for number of students.

P4. Write the Java Code program to create a class called COMPLEX and
implement the following overloading functions ADD that return a COMPLEX
number.
I. ADD (a, s2) - where a is an integer (real part) and s2 is a complex number.
II. ADD (s1, s2)-where s1 & s2 are complex numbers.
package R110212055.Saurabh.Q4;
import java.util.Scanner;
public class Complex
{
int real,imaginary;
void get_data()
{
Scanner sc = new Scanner(System.in);
System.out.print(" Enter the Real Part: ");
real = sc.nextInt();
System.out.print(" Enter the Imaginary Part: ");
imaginary = sc.nextInt();
}
void put_data()
{
System.out.println(" Complex No. is : "+this.real+""
+ "+i"+this.imaginary);
}
Complex Add(Complex s1,Complex s2)
{
this.real = s1.real + s2.real;
this.imaginary = s1.imaginary + s2.imaginary;
return this;
}
Complex Add(int a,Complex s2)

{
this.real = a + s2.real;
this.imaginary = s2.imaginary;
return this;
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Complex s1 = new Complex();
Complex s2 = new Complex();
Complex s3 = new Complex();
Complex s4 = new Complex();
int a;
Scanner sc = new Scanner(System.in);
System.out.print(" Enter a no. : ");
a = sc.nextInt();
s1.get_data();
s2.get_data();
s3.Add(a, s2);
System.out.println(" Adding: ");
System.out.println(" a = "+a);
s2.put_data();
System.out.println(" Result: ");
s3.put_data();
s4.Add(s1, s2);
System.out.println(" Adding: ");
s1.put_data();
s2.put_data();
System.out.println(" Result: ");
s4.put_data();
}
}

LAB EXPERIMENT 2
Title: JDBC
Objective: After these lab exercises students will be in position to clear the
concept of JDBC and how to connect the application to the different databases.
P1. Program to insert a record into a table student by creating a DSN in MS Access
database.
package R110212055.Saurabh.Q1;
import java.sql.*;
public class Db1
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:Saurabh");
Statement stmt = con.createStatement();
int i = stmt.executeUpdate("create table TABLE1(eid int, name
varchar(30))");
System.out.println(i);
int j = stmt.executeUpdate("insert into TABLE1
values(1,'SaurabhGaumat')");
System.out.println(j);
stmt.close();
con.close();
}
}

P2. Program to select the data from a table student by creating a DSN in MS
Access database.
package R110212055.Saurabh.Q2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class C2
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:Saurabh");
Statement stmt = con.createStatement();
ResultSet rs= stmt.executeQuery("select * from TABLE1");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
stmt.close();
con.close();
}
}

P3. Program to modify/update the record into a table student by creating a DSN in
MS Access Database.
package R110212055.Saurabh.Q3;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class C3
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:Saurabh");
Statement stmt = con.createStatement();
int i= stmt.executeUpdate("alter table TABLE1 ADD address
varchar(40)");
System.out.println(i);
stmt.close();
con.close();
}
}

P4. Program to select the data by using prepared statement from a table student by
creating a DSN in MS Access Database.
package R110212055.Saurabh.Q4;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class C4
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:Saurabh");
String sql= "update TABLE1 set name = ? where eid = ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(2, 1);
pstmt.setString(1, "SaurabhGaumat");
int rows= pstmt.executeUpdate();
System.out.println("Rows Impacted: "+rows);
pstmt.close();
con.close();
}
}

P5. Program to demonstrate the functionalities of execute function to select and


insert a record from a table student by creating a DSN in MS Access Database.
package R110212055.Saurabh.Q5
import java.sql.*;
public class C5
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("sun.odbc.jdbc.Driver");
Connection con =
DriverManager.getConnection(jdbc:odbc:Saurabh);
Statement stmt = con.createStatement();
int i= stmt.executeUpdate("create table MydbSG(name varchar(20), id
integer)");
System.out.println(i);
int j= stmt.executeUpdate("insert into MydbSG values(Saurabh,
2291)");
System.out.println(j);
Stmt.close();
con.close();
}
}

LAB EXPERIMENT 3
Title: JDBC using MYSQL
Objective: After these lab exercises students will be in position to clear the
concept of JDBC and how to connect the application to the different databases.
P1. Program to insert a record into a table student by creating a database in
MYSQL/DB2 database.
package R110212055.Saurabh.Q1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class C1
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbSaurabh",
"root","admin");
Statement stmt = con.createStatement();
int i= stmt.executeUpdate("create table Student(eid int, name
varchar(20))");
System.out.println(i);
int j= stmt.executeUpdate("insert into Student
values(1,'SaurabhGaumat')");
System.out.println(j);

int k= stmt.executeUpdate("insert into Student


values(2,'SaurabhGaumat')");
System.out.println(k);
stmt.close();
con.close();
}
}

P2. Program to select the data from a table student by creating a database in
MYSQL/DB2 database.
package R110212055.Saurabh.Q2;
import java.sql.*;
public class C2
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbSaurabh",
"root","admin");
Statement stmt = con.createStatement();
ResultSet rs= stmt.executeQuery("select * from Student");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
stmt.close();
con.close();
}
}

P3. Program to modify/update the record into a table student by creating a database
in MYSQL/DB2 database.
package R110212055.Saurabh.Q3;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class C3
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbSaurabh",
"root","admin");
Statement stmt = con.createStatement();
int i= stmt.executeUpdate("alter table Student ADD address
varchar(40)");
System.out.println(i);
stmt.close();
con.close();
}
}

P4. Program to select the data by using prepared statement from a table student in
MYSQL/DB2 database.
package R110212055.Saurabh.Q4;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class C4
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbSaurabh",
"root","admin");
String sql= "update student set name = ? where eid = ?";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setInt(2, 1);
pstmt.setString(1, "SaurabhGaumat");
int rows= pstmt.executeUpdate();
System.out.println("Rows Impacted: "+rows);
pstmt.close();
con.close();
}
}

P5. Program to demonstrate the functionalities of execute function to select and


insert a record from a table student by creating a database in MYSQL/DB2
database.
package R110212055.Saurabh.Q5
import java.sql.*;
public class C5
{
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException
{
// TODO Auto-generated method stub
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbSaurabh",
"root","admin");
Statement stmt = con.createStatement();
int i= stmt.executeUpdate("create table MydbSG(name varchar(20), id
integer)");
System.out.println(i);
int j= stmt.executeUpdate("insert into MydbSG values("Saurabh",
2291)");
System.out.println(j);
Stmt.close();
con.close();
}
}

Das könnte Ihnen auch gefallen