JP Lab Manual
JP Lab Manual
LABORATORY MANUAL
DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
Vision
To acknowledge quality education and instill high patterns of discipline making the
students technologically superior and ethically strong which involves the
improvement in the quality of life in human race.
Mission
To achieve and impart holistic technical education using the best of infrastructure,
outstanding technical and teaching expertise to establish the students into
competent and confident engineers.
Evolving the center of excellence through creative and innovative teaching
learning practices for promoting academic achievement to produce internationally
accepted competitive and world class professionals.
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
articulate, analyze, solve complex problems, and make decisions. These are
essential to address the challenges of complex and computation intensive
problems increasing their productivity.
2. To facilitate the graduates with the technical skills that prepare them for
3. To facilitate the graduates with the soft skills that include fulfilling the mission,
To facilitate the graduates with the knowledge of professional and ethical responsibilities
by paying attention to grooming, being conservative with style, following dress codes,
safety codes,and adapting themselves to technological advancements.
PROGRAM SPECIFIC OUTCOMES (PSOs)
After the completion of the course, B. Tech Computer Science and Engineering, the
graduates will have the following Program Specific Outcomes:
problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
7. Environment and sustainability: Understand the impact of the professional
the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of
the engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multi disciplinary
environments.
12. Life- long learning: Recognize the need for, and have the preparation and ability to
Before start of the first lab they have to buy the record and bring the record to
the lab.
Regularly (Weekly) update the record after completion of the experiment and
get it corrected with concerned lab in-charge for continuous evaluation.
In case the record is lost inform the same day to the faculty in charge and get
the new record within 2 days the record has to be submitted and get it
corrected by the faculty.
If record is not submitted in time or record is not written properly, the
evaluation marks (5M) will be deducted.
Record 5 Marks
Total marks for lab internal are 25 Marks as per Autonomous (JNTUH.)
These 25 Marks are distributed as:
Average of day to day evaluation marks: 15 Marks
Lab Mid exam: 10 Marks
Page
S.No List of programs
no
Write a java program to find the Fibonacci series using recursive and non
1. 1
recursive functions
2. Write a java program to multiply two given matrices. 3
Write a java program that prompts the user for an integer and then printouts all
3. prime numbers up to that integer. 5
4. Write a java program that checks whether a given string is palindrome or not 6
A) Write an applet program that displays a simple message 7
5.
B)Write a Java program compute factorial value using Applet 8
Write a java program that works as a simple calculator. Use a Grid Layout to
6. arrange Buttons for digits and for the + - * % operations. Add a text field to 11
display the result.
7. Write a Java program for display the exception in a message dialog box 14
Write a Java program that implements a multi-thread application that has three
8. 16
threads
A)Write a java program that connects to a database using JDBC 18
B)Write a java program to connect to a database using JDBC and insert values
9. 19
into it
C): Write a java program to connect to a database using JDBC and delete
20
values from it
10. Write a java program to simulate a traffic light 22
Write a java program to create an abstract class named shape that contains an
empty method named number of sides (). Provide three classes named
11. trapezoid, triangle and Hexagon such that each one of the classes extends the 24
class shape. Each one of the class contains only the method number of sides ()
that shows the number of sides in the given geometrical figures.
12. Write a java program to display the table using labels in Grid layout 26
14. Write a Java program loads phone no, name from a text file using hash table 30
Implement the above program to load phone no, name from database instead
15. 31
of text file
Write a Java program that takes tab separated data from a text file and inserts
16. 33
them into a database.
17. Write a Java program that prints the meta-data of a given table 35
PROGRAM -1 Date:
Aim: Write a java program to find the Fibonacci series using recursive and non recursive
functions
Program:
//Class to write the recursive and non recursive functions.
class fib
{
int a,b,c;
// Non recursive function to find the Fibonacci series.
void nonrecursive(int n)
{
a=0;
b=1;
c=a+b;
System.out.print(b);
while(c<=n)
{
System.out.print(c);
a=b;
b=c;
c=a+b;
}
}
// Recursive function to find the Fibonacci series.
int recursive(int n)
{
if(n==0)
return (0);
if(n==1)
return (1);
else
return(recursive(n-1)+recursive(n-2));
}
}
// Class that calls recursive and non recursive functions .
class fib1
{
public static void main(String args[])
{
int n;
// Accepting the value of n at run time.
n=Integer.parseInt(args[0]);
System.out.println("the recursion using non recursive is"); // Creating object for the fib
class.fib f=new fib();
// Calling non recursive function of fib
class. f.nonrecursive(n);
System.out.println("the recursion using recursive is"); ffor(int i=0;i<=n;i++)
{
// Calling recursive function of fib class. int F1=f.recursive(i);
System.out.print(F1);
}
}
}
1|Page
Three Test Outputs:
EXERCISE:
1. Write a java program to print the multiplication table .
2. Write a java program to find the Factorial of a given integer using recursive and non
recursive functions
2|Page
PROGRAM -2 Date:
Aim: Write a java program to multiply two given matrices.
// Class to find multiplication of matrices.
class matri
{
public static void main(String args[])
{
// Accept the number of rows and columns at run time.
int m=Integer.parseInt(args[0]);
int n=Integer.parseInt(args[1]);
// Initialize the arrays.
int a[][]=new int[m][n]; int b[][]=new int[m][n]; int c[][]=new int[m][n]; int i=2;
// Loop to accept the values into a matrix.
for(int j=0;j<m;j++)
{for(int k=0;k<n;k++)
{
a[j][k]=Integer.parseInt(args[i]);
i++;
}
}
// Loop to accept the values into b matrix.
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
b[j][k]=Integer.parseInt(args[i]);
i++;
}
}
// Loop to multiply two matrices .
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
c[j][k]=0;
for(int l=0;l<m;l++)
{
c[j][k]=c[j][k]+(a[j][l]*b[l][k]);
}
}
}
// Loop to display the result .
for(int j=0;j<m;j++)
{
for(int k=0;k<n;k++)
{
System.out.print(c[j][k]);
}
System.out.println();
}
}
}
3|Page
Three test outputs:
4|Page
PROGRAM -3 Date:
Aim: Write a java program that prompts the user for an integer and then printouts all prime
numbers up to that integer
Program:
import java.lang.*;
class Prime
{
public static void main(String arg[])
{
int n,c,i,j;
n=Integer.parseInt(arg[0]);
System.out.println("prime numbers are");
for(i=1;i<=n;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c++;
}
if(c==2)
System.out.println(" "+i);
}
}
}
Three test outputs:
5|Page
PROGRAM -4 Date:
Aim: Write a java program that checks whether a given string is palindrome or not
Program:
// Class to find whether string is palindrome or not.
class palindrome
{
public static void main(String args[])
{
// Accepting the string at run time.
String s=args[0];
String s1=""; int l,j;
// Finding the length of the string.
l=s.length();
// Loop to find the reverse of the string.
for(j=l-1;j>=0;j--)
{
s1=s1+s.charAt(j);
}
// Condition to find whether two strings are equal // and display the message.
if(s.equals(s1))
System.out.println("String "+s+" is palindrome");
else
System.out.println("String "+s+" is not palindrome");
}
6|Page
PROGRAM -5 A) Date:
EXERCISE:1.Write an applet program that accepts an integer and display the factorial of a
given integer. 2Write an applet program that accepts an integer and display the prime
numbers up to that given integer.
7|Page
PROGRAM -5 B Date:
Aim: Write a Java program compute factorial value using Applet
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class FactorialApplet extends Applet implements ActionListener
{
/*<applet code="FactorialApplet" height=300 width=300>
</applet>*/
Label l1,l2;
TextField t1,t2;
Button b1;
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
l1=new Label("Enter the value:");
add(l1);
t1=new TextField(10);
add(t1);
l2=new Label("Factorial value is:");
add(l2);
t2=new TextField(10);
add(t2);
b1=new Button("Compute");
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if((e.getSource())==b1)
{
int value=Integer.parseInt(t1.getText());
int fact=factorial(value);
t2.setText(String.valueOf(fact));
}
}
int factorial(int n)
{
if(n==0)
return 1;
else
return n*factorial(n-1);
}
}
8|Page
Signature of the faculty
Exercise: write an applet program for displaying the circle in green color.
9|Page
PROGRAM -6 Date:
Aim: Write a java program that works as a simple calculator. Use a Grid Layout to arrange
Buttons for digits and for the + - * % operations. Add a text field to display the result.
Program:
import javax.swing.*;
import javax.swing.JOptionPane; import java.awt.*;
import java.awt.event.*;
10 | P a g e
panel.add(n9);
n9.addActionListener(this);
div=new JButton("/");
panel.add(div);
div.addActionListener(this);
n4=new JButton("4");
panel.add(n4);
n4.addActionListener(this);
n5=new JButton("5");
panel.add(n5);
n5.addActionListener(this);
n6=new JButton("6");
panel.add(n6);
n6.addActionListener(this);
mul=new JButton("*");
panel.add(mul);
mul.addActionListener(this);
n1=new JButton("1");
panel.add(n1);
n1.addActionListener(this);
n2=new JButton("2");
panel.add(n2);
n2.addActionListener(this);
n3=new JButton("3");
panel.add(n3);
n3.addActionListener(this);
minus=new JButton("-");
panel.add(minus);
minus.addActionListener(this);
dot=new JButton(".");
panel.add(dot);
dot.addActionListener(this);
n0=new JButton("0");
panel.add(n0); n0.addActionListener(this);
equal=new JButton("=");
panel.add(equal);
equal.addActionListener(this);
plus=new JButton("+");
panel.add(plus);
plus.addActionListener(this);
add(panel);
}
// Implementing method in ActionListener.
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==n1)
assign("1");
else if(ae.getSource()==n2)
assign("2");
else if(ae.getSource()==n3)
assign("3");
else if(ae.getSource()==n4)
11 | P a g e
assign("4");
else if(ae.getSource()==n5)
assign("5");
else if(ae.getSource()==n6)
assign("6");
else if(ae.getSource()==n7)
assign("7");
else if(ae.getSource()==n8)
assign("8");
else if(ae.getSource()==n9)
assign("9");
else if(ae.getSource()==n0)
assign("0");
else if(ae.getSource()==dot)
{
if(((result.getText()).indexOf("."))==-1) result.setText(result.getText()+"."); }
else if(ae.getSource()==minus)
{
preRes=Double.parseDouble(result.getText()); lastCommand="-";
result.setText("0");
}
else if(ae.getSource()==div)
{
preRes=Double.parseDouble(result.getText());
lastCommand="/";
result.setText("0");
}
else if(ae.getSource()==equal)
{
secVal=Double.parseDouble(result.getText());
if(lastCommand.equals("/"))
res=preRes/secVal;
else if(lastCommand.equals("*"))
res=preRes*secVal;
else if(lastCommand.equals("-"))
res=preRes-secVal;
else if(lastCommand.equals("+"))
res=preRes+secVal;
result.setText(" "+res); lastCommand="=";
}
else if(ae.getSource()==mul)
{
preRes=Double.parseDouble(result.getText());
lastCommand="*";
result.setText("0");
}
else if(ae.getSource()==plus)
{
preRes=Double.parseDouble(result.getText());
lastCommand="+";
result.setText("0");
}
}
12 | P a g e
}
Calculator.html:
<applet code="Calculator" width=200 height=300> </applet>
13 | P a g e
PROGRAM -7 Date:
Aim: Write a Java program for display the exception in a message dialogbox
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class NumOperations extends JApplet implements ActionListener
{
/*<applet code="NumOperations" width=300 height=300>
</applet>*/
JLabel l1,l2,l3;
JTextField t1,t2,t3;
JButton b1;
public void init()
{
Container contentPane=getContentPane();
contentPane.setLayout(new FlowLayout());
l1=new JLabel("Enter num1:");
contentPane.add(l1);
t1=new JTextField(15);
contentPane.add(t1);
l2=new JLabel("Enter num2:");
contentPane.add(l2);
t2=new JTextField(15);
contentPane.add(t2);
l3=new JLabel("The Result");
contentPane.add(l3);
t3=new JTextField(15);
contentPane.add(t3);
b1=new JButton("Divide");
contentPane.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try
{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t1.getText());
Float c=Float.valueOf(a/b);
t3.setText(String.valueOf(c));
}
catch(NumberFormatException e1)
{
JOptionPane.showMessageDialog(this,"Not a valid number");
}
catch(ArithmeticException e2)
{
JOptionPane.showMessageDialog(this,e2.getMessage());
}
}
14 | P a g e
}
}
15 | P a g e
PROGRAM -8 Date:
Aim: Write a Java program that implements a multi-thread application that has three threads
Program:
}
System.out.println(name+""+"exiting");
}
}
// Class that takes the thread name and run the main thread.
class multithread
{
public static void main(String args[ ])
{ // Creating child threads.
new NewThread("one"); new NewThread("two");
new NewThread("three");
// Block that may generate the exception.
try
{
for(int i=5;i>0;i--)
{
System.out.println("main thread"+i);
Thread.sleep(10000);
}
}
16 | P a g e
// Block that catch the exception.
catch(Exception e)
{
System.out.println("main thread interrupted");
}
System.out.println("main thread exiting");
}
}
17 | P a g e
PROGRAM -9 A) Date:
Aim: Write a java program that connects to a database using JDBC
Program:
import java.sql.Connection;
import java.sql.DriverManager;
public class PostgreSQLJDBC
{
public static void main(String args[])
{
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager .getConnection("jdbc:postgresql://localhost:5432/testdb",
"postgres", "123");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName()+": "+e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
}
}
18 | P a g e
Program
B) : Write a java program to connect to a database using JDBC and insert values into it
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class PostgreSQLJDBC
{
public static void main(String args[])
{
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/testdb",
"manisha", "123");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "
+ "VALUES (1, 'Paul', 32, 'California', 20000.00 );";
stmt.executeUpdate(sql);
stmt.close();
c.commit();
c.close();
} catch (Exception e) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Records created successfully");
}
}
19 | P a g e
Signature of the faculty
Program
C) : Write a java program to connect to a database using JDBC and delete values from it
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
stmt = c.createStatement();
String sql = "DELETE from COMPANY where ID=2;";
stmt.executeUpdate(sql);
c.commit();
ResultSet rs = stmt.executeQuery( "SELECT * FROM COMPANY;" );
while ( rs.next() ) {
20 | P a g e
int id = rs.getInt("id");
String name = rs.getString("name");
int age = rs.getInt("age");
String address = rs.getString("address");
float salary = rs.getFloat("salary");
System.out.println( "ID = " + id );
System.out.println( "NAME = " + name );
System.out.println( "AGE = " + age );
System.out.println( "ADDRESS = " + address );
System.out.println( "SALARY = " + salary );
System.out.println();
}
rs.close();
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Operation done successfully");
}
}
21 | P a g e
PROGRAM -10 Date:
Aim: Write a java program to simulate a traffic light
Program:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
// Class that allows user to select the traffic lights.
public class Trafficlight extends JFrame implements ItemListener
{
JRadioButton redbut,yellowbut,greenbut;
public Trafficlight()
{
Container c = getContentPane();
c.setLayout(new FlowLayout());
// Create the button group.
ButtonGroup group= new ButtonGroup();
redbut = new JRadioButton("Red");
yellowbut = new JRadioButton("Yellow");
greenbut = new JRadioButton("Green");
group.add(redbut);
group.add(yellowbut);
group.add(greenbut);
// Add the buttons to the container.
c.add(redbut);
c.add(yellowbut);
c.add(greenbut);
// Add listeners to perform action
redbut.addItemListener(this);
yellowbut.addItemListener(this);
greenbut.addItemListener(this);
addWindowListener(new WindowAdapter()
{
// Implement methods in Window Event class.
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
} );
setTitle("Traffic Light ");
setSize(250,200);
setVisible(true);
}
// Implement methods in Item Event class.
public void itemStateChanged(ItemEvent e)
{
String name= " ",color=" ";
if(redbut.isSelected() )
name = "Red";
else if(yellowbut.isSelected() )
name = "Yellow";
else if(greenbut.isSelected() )
name = "Green";
22 | P a g e
JOptionPane.showMessageDialog(null,"The "+name+" light is simulated, "MessgeBox",
JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String args[] )
{
new trafficlight();
}
}
EXERCISE:
Write a java program that lets the user select one the three options: IT, CSE or ECE. When a
radio button is selected, the radio button is turned on and only one option can be on at a time
no option is on when program starts.
23 | P a g e
PROGRAM -11 Date:
Aim: Write a java program to create an abstract class named shape that contains an empty
method named number of sides (). Provide three classes named trapezoid, triangle and
Hexagon such that each one of the classes extends the class shape. Each one of the class
contains only the method number of sides () that shows the number of sides in the given
geometrical figures.
Program:
}
}
// Class that create objects and call the method.
class ShapeDemo
{
public static void main(String args[])
{
Trapezoid obj1 = new Trapezoid();
Triangle obj2 = new Triangle();
Hexogon obj3 = new Hexogon();
obj1.numberOfSides();
obj2.numberOfSides();
obj3.numberOfSides(); }
}
24 | P a g e
Three test outputs:
25 | P a g e
PROGRAM -12 Date:
Aim:Write a java program to display the table using labels in Grid layout
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
public class TableDemo extends JFrame
{
int i=0;
int j=0;
Object TabData[][]=new Object[5][2];
JTable mytable;
FileInputStream fr;
DataInputStream in;
public TableDemo()
{
String str=" ";
Container contentpane=getContentPane();
contentpane.setLayout(new BorderLayout());
final String[] Column={","};
try
{
FileInputStream fr=new FileInputStream("table.txt");
DataInputStream in=new DataInputStream(fr);
if((str=in.readLine())!=null)
{
StringTokenizer s=new StringTokenizer(str,",");
while(s.hasMoreTokens())
{
for(int k=0;k<2;k++)
{
Column[k]=s.nextToken();
}
}
}
while((str=in.readLine())!=null)
{
StringTokenizer s=new StringTokenizer(str,",");
while(s.hasMoreTokens())
{
for(j=0;j<2;j++)
{
TabData[i][j]=s.nextToken();
}
i++;
}
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
26 | P a g e
mytable=new JTable(TabData,Column);
int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane scroll=new JScrollPane(mytable,v,h);
contentpane.add(scroll,BorderLayout.CENTER);
}
public static void main(String args[])
{
TableDemo t=new TableDemo();
t.setSize(300,300);
t.setVisible(true);
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
27 | P a g e
PROGRAM -13 Date:
Aim:Write a java program for handling mouse events
28 | P a g e
repaint();
}
mouseevent.html:
EXERCISE:
1.Write a java program for handling KEY BOARD events.
29 | P a g e
PROGRAM -14 Date:
Aim:Write a Java program loads phone no,name from a text file using hash table
Program:
// Demonstrate a Hashtable
import java.util.*;
class HTDemo {
public static void main(String args[]) {
Hashtable balance = new Hashtable();
Enumeration names;
String str;
double bal;
balance.put("John Doe", new Double(3434.34));
balance.put("Tom Smith", new Double(123.22));
balance.put("Jane Baker", new Double(1378.00));
balance.put("Todd Hall", new Double(99.22));
balance.put("Ralph Smith", new Double(-19.08));
// Show all balances in hash table.
names = balance.keys();
while(names.hasMoreElements()) {
str = (String) names.nextElement();
System.out.println(str + ": " +
balance.get(str));
}
System.out.println();
// Deposit 1,000 into John Doe's account
bal = ((Double)balance.get("John Doe")).doubleValue();
balance.put("John Doe", new Double(bal+1000));
System.out.println("John Doe's new balance: " +
balance.get("John Doe"));
}
}
Three test outputs:
Exercise:
Write a Java program loads list of student names and roll numbers from a text file
30 | P a g e
PROGRAM -15 Date:
Aim: Implement the above program to load phone no, name from database instead of text
file
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class PostgreSQLJDBC {
public static void main( String args[] )
{
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager
.getConnection("jdbc:postgresql://localhost:5432/testdb",
"manisha", "123");
System.out.println("Opened database successfully");
stmt = c.createStatement();
String sql = "CREATE TABLE COMPANY " +
"(ID INT PRIMARY KEY NOT NULL," +
" NAME TEXT NOT NULL, " +
" AGE INT NOT NULL, " +
" ADDRESS CHAR(50), " +
" SALARY REAL)";
stmt.executeUpdate(sql);
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Table created successfully");
}
}
Three test outputs:
31 | P a g e
PROGRAM -16 Date:
Aim:Write a Java program that takes tab separated data from a text file and inserts them into
a database.
Program:
import java.io.BufferedReader;
import java.io.FileReader;
/**
* Creating a buffered reader to read the file
*/
BufferedReader bReader = new BufferedReader(
new FileReader(dataFileName));
String line;
/**
* Looping the read block until all lines in the file are read.
*/
while ((line = bReader.readLine()) != null) {
/**
* Splitting the content of tabbed separated line
*/
String datavalue[] = line.split("\t");
String value1 = datavalue[0];
String value2 = datavalue[1];
int value3 = Integer.parseInt(datavalue[2]);
double value4 = Double.parseDouble(datavalue[3]);
/**
* Printing the value read from file to the console
*/
System.out.println(value1 + "\t" + value2 + "\t" + value3 + "\t"
+ value4);
}
bReader.close();
}
32 | P a g e
Signature of the faculty
Exercise:
Write a program to reverse the specified n number of characters from the given text file and
insert the data into database.
33 | P a g e
PROGRAM -17 Date:
Aim: Write a Java program that prints the meta-data of a given table
Program:
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDBCDriverInformation {
static String userid="scott", password = "tiger";
static String url = "jdbc:odbc:bob";
static Connection con = null;
public static void main(String[] args) throws Exception {
Connection con = getOracleJDBCConnection();
if(con!= null){
System.out.println("Got Connection.");
DatabaseMetaData meta = con.getMetaData();
System.out.println("Driver Name : "+meta.getDriverName());
System.out.println("Driver Version : "+meta.getDriverVersion());
}else{
System.out.println("Could not Get Connection");
}
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, userid, password);
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
return con;
}
34 | P a g e
Signature of the faculty
Exercise: Write a Java program that prints the meta-data of a given hash table.
35 | P a g e